Solved

How to pass a NULL to SQL SmallDateTime value?

Posted on 2010-11-24
3
1,226 Views
Last Modified: 2012-05-10
I have two text boxes that may or may not be filled in, depending on a RadioButtonList selection.

Below .Value = "NULL" doesn't work.  How can I send NULL to the SQL 2005 field?
If radStateContract.SelectedIndex = 0 Then
      DBCmd.Parameters.Add("@StateContractNo", SqlDbType.VarChar).Value = txtStateContractNo.Text
      DBCmd.Parameters.Add("@StateContractEndDate", SqlDbType.SmallDateTime).Value = CType(txtStateContractEndDate.Text, DateTime)
Else
      DBCmd.Parameters.Add("@StateContractNo", SqlDbType.VarChar).Value = "N/A"
      DBCmd.Parameters.Add("@StateContractEndDate", SqlDbType.SmallDateTime).Value = "NULL"
End If

Open in new window

0
Comment
Question by:megnin
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Gorkem Yuksel earned 500 total points
ID: 34207239
Hi,

You can use the dbnull object..

DBCmd.Parameters.Add("@StateContractEndDate", SqlDbType.SmallDateTime).Value = DBNull.Value;

I hope this helps,

G.
0
 
LVL 1

Author Closing Comment

by:megnin
ID: 34207280
Yes.  Wonderful.  Thank you.  I had tried "= DBNull" but didn't think to add ".Value".  Yeah, I'm a beginner.  ;-)
0
 
LVL 9

Expert Comment

by:Gorkem Yuksel
ID: 34207305
No problem.. glad I could help! :)

G.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question