Solved

How to pass a NULL to SQL SmallDateTime value?

Posted on 2010-11-24
3
1,218 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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