Q: date as null

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I am calling a stored procedure to update my table.
If one of the date on the screen left empty, I need to send date as null.
Since MyDate=â€â€ gives error in asp.net, how should I do this?
Thanks,
Jim.
 
Should I do this in asp.net? MyDate=DBNull.Value is not recognized in my
application. I did Imports System.Object, it is still teh same.
 
Jim,
You could set the parameter in the stored procedure to have a
default value of null, then if the user doesn't enter a date in the field
you can still pass the parameter with the date information, just don't set
the value of the parameter and the stored procedure will automatically use
null.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
The Date variable type cannot be null. It must have a value.
Most people use Date.MinValue (or Date.MaxValue) to represent a null date in
their code.

Example:
Dim MyDate as Date = Date.MinValue

As for inserting it in the database, the other guys already specified that
DBNull.Value is what you'll want to use.
 
I did Date = Date.MinValue and Date has only time value liek 12:00:00 and
when I try to call stored procedure it gives me out of range. Does
Date.MinValue give a default date? If yes, what is it? I am using 1/1/1950 as
default date.
 
Date.MinValue = January 1, 0001.
This is why the stored procedure chokes on it.
You need to check for this special value and instead pass DBNull.Value to
the stored procedure.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
 
Hello JIM.H.,

If you need to pass it to a stored procedure, and you require a value, you
can use SqlDateTime.MinValue. If you allow nulls, just use DBNull.Value.
 
Back
Top