Assign blank date

  • Thread starter Thread starter Ashoo
  • Start date Start date
A

Ashoo

I am trying to insert a record with a blank date field. I
get an error saying can not convert "" string to date
type. Since null is allowed on that column I try to assign
a null value... still an error came up saying can not
convert DBnull type to date type. I am not sure what to
try next. Please help.
 
SQL Server?

If so, you can add a parameter to your statement (if stored procedure,
nothing needed, as you will already be using parameters). Set the parameter
to System.Data.SqlTypes.SqlDateTime.Null. Everything should work fine.

If you want to set it up in a concatenated SQL string, you simple insert the
word NULL, with no ''.

sql = "INSERT INTO MyTable(MyID, MyDate) VALUES " & _
"(" & MyID & ", NULL)"

I like the parameter better.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top