To pass a NULL value to a Parameter in VB.NET pass Nothing, in C# pass Null.
Another approach that I discuss in the book is to set the default value of
the Parameter to NULL. In this case you simply don't add the Parameter to
the Parameters collection and the default value is assumed.
hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit
www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
[quoted text, click to view] "Scott M." <s-mar@nospam.nospam> wrote in message
news:eTDgBtOwHHA.484@TK2MSFTNGP06.phx.gbl...
> If I'm not mistaken (and I could be), if you insert a record but omit
> certain fields, then those fields will become null in the database. For
> example,
>
> Dim dtDate as Date = CDate(txtDate.text,Date)
>
> Now, if txtDate.text were to be an empty string, then dtDate would have no
> value. Later, when you insert dtDate into your database, it will become
> null.
>
> -Scott
>
>
> "Brad Pears" <bradp@truenorthloghomes.com> wrote in message
> news:%23h1DUvAwHHA.1164@TK2MSFTNGP02.phx.gbl...
>>I have a vb.net 2005 project using an sql server 2000 backend db. I want
>>to be able to insert null values into two of the date fields on new
>>inserts (there may be a valid date - but possibly it will be empty). These
>>two fields are defined as "smalldatetime" in sql server.
>>
>> In my vb.net code, I am trying to set up the date variable I wan tto pass
>> as follows but I keep getting an error indicating that "value of type
>> 'System.DBNull' can not be converted to 'Date'.
>>
>> dim dtDate as date =system.DbNull.value
>>
>> How do I get a date variable to be initialized to null so I can pass it
>> to my stored procedure?
>>
>> Thanks, Brad
>>
>
>