[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to pass a NULL to SQL SmallDateTime value?

Posted on 2010-11-24
3
Medium Priority
?
1,265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Gorkem Yuksel earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 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