Link to home
Start Free TrialLog in
Avatar of Jimbo99999
Jimbo99999Flag for United States of America

asked on

VB.Net - SQL Query to Update Field to Null

Good Day Experts!

Another first in my coding career.  In my VB.net program, I need to update a SQL table field to Null.  However, in my query I am not sure how to specify to set the field to Null.

How to I set to Null?

Update Customers set TimeEntered = NULL ?

Thanks,
jimbo99999
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>Update Customers set TimeEntered = NULL ?
In T-SQL this is correct for all rows.  
If you only wish to do this for a subset of rows, you'll have to add a WHERE clause at the end.

like..

Update Customers set TimeEntered = NULL WHERE id = SomeNumber
Either:
Update Customers set TimeEntered = NULL
Or:
Update Customers set TimeEntered = ""
Depending on where you are writing it to.
Double quotes is a blank field and will be seen as a NULL.
@Sodea63: Null and blank are two different values.
update yourtable
  set yourcolumn = nullif(yourcolumn,yourcolumn)
 where yourcolumn is not null
If you insert NULL ., you need to handle NULL while fetching also in vb.net code


if Not isdbnull(reader.item("CreateDate") then
//Your code here
End if
Avatar of Jimbo99999

ASKER

Thanks,
jimbo99999