Date conversion failure

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

Guest

I need to return null for a date field. Here is what I am doing, but it isnt working. What am I doing wrong?

private DateTime ArriveTime()
{
return (DBNull.Value);
}
 
Chris:

DateTime is a value type and I don't belive it can cast to DBNull.Value or
Null. If you want to use DateTime, I think you'll need to use
DateTime.MinValue or use a different return type.
Chris said:
I need to return null for a date field. Here is what I am doing, but it
isnt working. What am I doing wrong?
 
Hi,

William Ryan eMVP said:
Chris:

DateTime is a value type and I don't belive it can cast to DBNull.Value or
Null. If you want to use DateTime, I think you'll need to use
DateTime.MinValue or use a different return type.

William is correct here (actually he is alyways correct ;-) )
You might use object as return type.
Or you might check http://nullabletypes.sourceforge.net/ for nullable types.
 
Back
Top