HighTechTalks DotNet Forums  

How to pass a null value to SQL insert statement in vb.net

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss How to pass a null value to SQL insert statement in vb.net in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Liam Mac
 
Posts: n/a

Default How to pass a null value to SQL insert statement in vb.net - 06-27-2006 , 06:38 AM






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

Reply With Quote
  #2  
Old   
pvdg42
 
Posts: n/a

Default Re: How to pass a null value to SQL insert statement in vb.net - 06-27-2006 , 09:02 AM







"Liam Mac" <LiamMac (AT) discussions (DOT) microsoft.com> wrote

Quote:
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
What constraints are defined for the field in question in the database
table?




Reply With Quote
  #3  
Old   
pvdg42
 
Posts: n/a

Default Re: How to pass a null value to SQL insert statement in vb.net - 06-27-2006 , 09:26 AM




"Liam Mac" <LiamMac (AT) discussions (DOT) microsoft.com> wrote

Quote:
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
This article may be helpful:

http://msdn.microsoft.com/library/de...mberstopic.asp




Reply With Quote
  #4  
Old   
alv0873
 
Posts: n/a

Default Re: How to pass a null value to SQL insert statement i... - 07-26-2006 , 11:30 AM



Try using sqldatenull. I have used this code and it worked for me, see sample below, hope this helps:

sql.commandtext="insert into TEST_TABLE (datefield) VALUES (@DATEVALUE)"

If (datefield = "") Then
sql.Parameters("@DATEVALUE").Value = sqldatenull
Else
sql.Parameters("@DATEVALUE").Value = datefield
End If





Reply With Quote
  #5  
Old   
ashrafs
 
Posts: n/a

Default Re: How to pass a null value to SQL insert statement i... - 09-14-2006 , 09:39 PM



Use the DBNull.Value in your SQL Query. That should work.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.