Solved

How to pass a NULL to SQL SmallDateTime value?

Posted on 2010-11-24
3
1,197 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
Comment Utility
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
Comment Utility
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
Comment Utility
No problem.. glad I could help! :)

G.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now