如何处理来自SQL Server的DBNull DateTime字段?

Mik*_*lls 3 c# null datetime dbnull

当我检索具有null DataTime字段的行时,我收到此错误:

'srRow.Closed_Date'引发了'System.Data.StrongTypingException'类型的异常

我该如何正确处理这些?

Mic*_*tta 6

您可以在检索值之前检查该列中的空值.

if (!srRow.IsClosed_DateNull())
{
  myDate = srRow.Closed_Date;
}
Run Code Online (Sandbox Code Playgroud)