• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1327
  • Last Modified:

How to pass a NULL to SQL SmallDateTime value?

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)
      DBCmd.Parameters.Add("@StateContractNo", SqlDbType.VarChar).Value = "N/A"
      DBCmd.Parameters.Add("@StateContractEndDate", SqlDbType.SmallDateTime).Value = "NULL"
End If

Open in new window

  • 2
1 Solution
Gorkem YukselCommented:

You can use the dbnull object..

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

I hope this helps,

megninAuthor Commented:
Yes.  Wonderful.  Thank you.  I had tried "= DBNull" but didn't think to add ".Value".  Yeah, I'm a beginner.  ;-)
Gorkem YukselCommented:
No problem.. glad I could help! :)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now