vb.net, MSSQL, and null dates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an application where a database entity that progresses through a
cycle. As it completes a step along the cycle, a todays date is assign to
one of the date columns in the table row. However at the beginning of the
cycle many of the dates hold null values.

Is there a simple way that I can read a date with a null value into a class
object I have created and turn around a write it back out to the table with
again with a null value?

How do people handle null date values coming into VB? My only option has
been to convert it to some fictious date value and program accordingly. Any
suggestions? Any online resources?

Thanks!
 
I use stored procedures or sql as strings to read and write.
Stored procedures are my preference, but not as flexible as building a
sql string.
Either way, there's a SQL insert or update string somewhere.
You can insert NULL by missing the field out the list, assuming there
is no default value on it.
You can update a field to null by setting it to NULL.
"Update mytable set myfield = NULL where...."

You can also leave a field as null by not updating the field ( or row
).
 
if you want to set a field to null in VB.NET code, set the field equal to
System.DbNull.Value.

You can also check if a value is null using this same object.

Hope it helps
Chris
 
I have tried to use that method but variables defined with a date will not
accept system.dbnull.value. It says that it can not be converted to a date.

Thanks
 
Lakota,

Are you using a datatable or a datareader, probably it is than easier to
answer you.
Or maybe even a datatable with binding to a control, what is again a little
bit else, where it differs if it is a "datasource" kind of control or a
databinding kind of control.

Maybe you can tell that?

Cor
 
Back
Top