How to assign a null value to a date variable

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

Guest

Hi All,

Can anyone direct me or provide advice on how I can assign a null value to a
date variable in vb.net.
Basically what I'm doing is that I'm looping through a recordset where I
have three date fields that may or maynot have date values, if no date values
exists in the source field, the value is null. but when I pass a record from
the recordset to SQL command parameter query for record insertion into a
different table, the date values that are blank are inserting a date stamp of
00/00/1900 00:00:00 into my destination table. So is there anyway that I can
assign a null value to vb.net date variable so that when the date field is
blank a null value is inserted by my SQL insert statment.

many thanks,
Liamo
 
Liam,

To give any answer on this I think that you has to tell what database you
use.

The date you shows let me think that you use the smalldatetime from
Microsoft, but it can of course be any other datebase. DateTime is in memory
01/01/00 00:00:00 and in SQL/Jet server 01/01/1753

Cor
 
Hello, Liam!

[skipped]

LM> So is there anyway that I can assign a null value to vb.net date
LM> variable so that when the date field is blank a null value is inserted
LM> by my SQL insert statment.

Assign DbNull.Value to that field, this will repsent null value

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
look at either Nullable(of DateTime)
or the sqlDate datatype (assuming you are using sql server - there are
equivalents for other databases)

hth

guy
 
Back
Top