DBNull

  • Thread starter Thread starter JD
  • Start date Start date
J

JD

I'm not sure which group to send this to>

I have a windows form with a text box that I want to send the data entry to
SQL using a stored procedure.

I add the parameter:
Dim prm as
sqlclient.sqlparameter=sqlcm.Parameters.add("@WaterTemp",Sqldbtype.decimal,9
)

get the value from the text box:
prm.value=me.textbox.text

I execute the stored Procedure:
Sqlcm.ExecuteNonQuery()

I get an error 'Input string was not in right format' and that is because I
do not put a value in the textbox because no data is available.

The SQL table column is set to allow nulls.

I think I need to use DBNull but I don't know how. The ' help' is not very
helpful!

Can anyone please help me?

thanks
 
You could try the following:

If Me.TextBox1.Text.Length = 0 Then
prm.Value = DBNull.Value
Else
prm.Value = Integer.Parse(Me.TextBox1.Text)
End If
 
Thanks Rob that worked nicely.
jd

Rob Windsor said:
You could try the following:

If Me.TextBox1.Text.Length = 0 Then
prm.Value = DBNull.Value
Else
prm.Value = Integer.Parse(Me.TextBox1.Text)
End If


--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada


JD said:
I'm not sure which group to send this to>

I have a windows form with a text box that I want to send the data entry to
SQL using a stored procedure.

I add the parameter:
Dim prm as
sqlclient.sqlparameter=sqlcm.Parameters.add("@WaterTemp",Sqldbtype.decimal,9
)

get the value from the text box:
prm.value=me.textbox.text

I execute the stored Procedure:
Sqlcm.ExecuteNonQuery()

I get an error 'Input string was not in right format' and that is
because
I
do not put a value in the textbox because no data is available.

The SQL table column is set to allow nulls.

I think I need to use DBNull but I don't know how. The ' help' is not very
helpful!

Can anyone please help me?

thanks
 
Thanks Rob, that worked nicely

jd
Rob Windsor said:
You could try the following:

If Me.TextBox1.Text.Length = 0 Then
prm.Value = DBNull.Value
Else
prm.Value = Integer.Parse(Me.TextBox1.Text)
End If


--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada


JD said:
I'm not sure which group to send this to>

I have a windows form with a text box that I want to send the data entry to
SQL using a stored procedure.

I add the parameter:
Dim prm as
sqlclient.sqlparameter=sqlcm.Parameters.add("@WaterTemp",Sqldbtype.decimal,9
)

get the value from the text box:
prm.value=me.textbox.text

I execute the stored Procedure:
Sqlcm.ExecuteNonQuery()

I get an error 'Input string was not in right format' and that is
because
I
do not put a value in the textbox because no data is available.

The SQL table column is set to allow nulls.

I think I need to use DBNull but I don't know how. The ' help' is not very
helpful!

Can anyone please help me?

thanks
 
Back
Top