I have a text box on a web form in visual studio.net that a user enters a
number in.
If they blank out the text box then I want to put a null value back into the
database field.
I want to return the value to NULL like txtWaterDischargeRate =
System.DBNull.Value instead of Nothing but I get an error
Can't convert NULL to integer
How can I enter a null in the database field on MS SQL Server?
Thanks
Hi
I am not sure what you are trying to do and I'm not a webform expert, but
you should be able to set may want to try something like checking the field's
data length in the application and passing DBNULL.value to the stored
procedure.
Alternatively you may be able to use a special value (say -1) and use
NULLIF(@.parameter,-1) in your insert statement.
John
"Craig" wrote:
> I have a text box on a web form in visual studio.net that a user enters a
> number in.
> If they blank out the text box then I want to put a null value back into the
> database field.
> I want to return the value to NULL like txtWaterDischargeRate =
> System.DBNull.Value instead of Nothing but I get an error
> Can't convert NULL to integer
> How can I enter a null in the database field on MS SQL Server?
> Thanks
>
>
>
|||Sample code.....
With DataSetLocationsForm1.tblLocations(0)
.WaterDischargeCost = txtWaterDischargeCost.Text
.MoreFields = txtOtherTextboxes.Text
End With
SqlDataAdapter1.Update(DataSetLocationsForm1)
The WaterDischargeCost field in the database is an type real. If they blank
out the text box and click the SAVE button on an existing record I get an
error "Can't convert NULL to integer"
I want to put a null value back into the database field
How do I do this?
Thanks
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...[vbcol=seagreen]
> Hi
> I am not sure what you are trying to do and I'm not a webform expert, but
> you should be able to set may want to try something like checking the
> field's
> data length in the application and passing DBNULL.value to the stored
> procedure.
> Alternatively you may be able to use a special value (say -1) and use
> NULLIF(@.parameter,-1) in your insert statement.
> John
> "Craig" wrote:
|||Hi Craig,
Thanks for your post.
From your descriptions, I understood you would like to know how to how to
handle NULL with SQL Server in VS.NET. If I have misunderstood your
concern, please feel free to point it out.
To better answer this question, I would recommand you raise the question in
ADO.NET or VS.NET managed newsgroup.
microsoft.public.dotnet.framework.adonet
microsoft.public.dotnet.framework
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
|||Hi
This is almost certainly because you are passing as string "NULL" and not
NULL itself.
Try something like (although the syntax may not be correct!)
IF txtWaterDischargeCost.length > 0
..WaterDischargeCost = txtWaterDischargeCost.Text
ELSE
..WaterDischargeCost = System.DBNull
You can use SQL profiler to see the SQL statement sent to the database and
verify what the command actually is.
John
"Craig" wrote:
> Sample code.....
> With DataSetLocationsForm1.tblLocations(0)
> .WaterDischargeCost = txtWaterDischargeCost.Text
> .MoreFields = txtOtherTextboxes.Text
> End With
> SqlDataAdapter1.Update(DataSetLocationsForm1)
> The WaterDischargeCost field in the database is an type real. If they blank
> out the text box and click the SAVE button on an existing record I get an
> error "Can't convert NULL to integer"
> I want to put a null value back into the database field
> How do I do this?
> Thanks
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...
>
>
|||If the column WaterDischargeCost is nullable (minoccurs = 0), then you can
use:
DataSetLocationsForm1.tblLocations(0).SetWaterDisc hargeCostNull()
to let the dataset set the value as null.
This works!!!!
"Craig" <NoSpam@.hotmail.com> wrote in message
news:O6UVrbCqFHA.3160@.TK2MSFTNGP14.phx.gbl...
> Sample code.....
> With DataSetLocationsForm1.tblLocations(0)
> .WaterDischargeCost = txtWaterDischargeCost.Text
> .MoreFields = txtOtherTextboxes.Text
> End With
> SqlDataAdapter1.Update(DataSetLocationsForm1)
> The WaterDischargeCost field in the database is an type real. If they
> blank out the text box and click the SAVE button on an existing record I
> get an error "Can't convert NULL to integer"
> I want to put a null value back into the database field
> How do I do this?
> Thanks
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment