I'm reading a record from a DB2 database via ODBC connection. The data is populated into an ODBCDataReader. As I'm going through my foreach loop I'm running into problems trying to parse the multiple different DateTime fields.
Some of the fields are null, some have null date time value (9999-12-31 24:00:00.000000) and some have valid date time values (2010-07-09 20:43:32.037234).
I've tried doing something like this to catch null date time errors:
if (!dr[dbFieldName].Equals(DBNull.Value))
{
if (dr.GetDate(dr.GetOrdinal(dbFieldName)).Equals(DateTime.Parse("9999-12-31 24:00:00.000000")))
{
fieldValues[tag] = "";
}
else
{
strValue = dr.GetDate(dr.GetOrdinal(dbFieldName)).ToString("s");
fieldValues[tag] = strValue.Trim();
}
}
The GetType().Name != "DBNull" seems to work for catching null values. However the next if statement throws an ArgumentOutOfRangeException error. This appears to happen on fields with the 9999-12-31 24:00:00.000000 values.
Is there a way to properly parse this? It seems like any way I try to evaluate these null date time fields a error is thrown.