views:

544

answers:

3

I am getting this error when I retrieve a row with a null DataTime field:

'srRow.Closed_Date' threw an exception of type 'System.Data.StrongTypingException'

How do I properly handle these?

+1  A: 

There's a reference here.

or possibly, can you modify your query to ensure the results are not null by using the IsNull operator?

Select (IsNull, SomeDateField, GetDate())
David Stratton
passing bogus dates instead of a null isn't the best choice here...
Scott Ivey
+3  A: 

You can check for a null value in that column before retrieving the value.

if (!srRow.IsClosed_DateNull())
{
  myDate = srRow.Closed_Date;
}
Michael Petrotta
+1 Good answer - yours should be the accepted answer, not the IsNull answer
Scott Ivey
A: 

Assuming you're using .NET, there are SqlTypes that can be used in a situation like this.

Tyler