How to test null date output parameter returned from a stored proc

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

Guest

I'm using the Microsoft Enterprise Data Access block to call the stored
procedure. One of the values the stored procedure returns is the stop date.
When the stop date is null, the program crashes. I would like to be able to
test for a null date, and then store the mindate value in the class
property.

I've tried the following, but it still crashes.

if (dbCommandWrapper.GetParameterValue("@StopDt") == null)
{
_StopDt = DateTime.MinValue;
}
else
{
_StopDt = Convert.ToDateTime(dbCommandWrapper.GetParameterValue("@StopDt"));
}

Any ideas?
Thanks,
Vern
 
Hi,

You should test with System.DBNull.Value
//Load
if ( reader["AcknowledgeBy"]==System.DBNull.Value )
DateTime ackdate = DateTime.MinValue ;
else
DateTime ackdate = Convert.ToDateTime( reader["AcknowledgeBy"]);


//Save
if (ackdate==DateTime.MinValue)
com.Parameters.Add("@ackdate", SqlDbType.DateTime).Value =
System.DBNull.Value

else
com.Parameters.Add("@ackdate", SqlDbType.DateTime).Value = ackdate ;


cheers,
 
Back
Top