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.
在通过ODBC连接从DB2数据库读取数据时遇到DateTime字段解析问题。遇到的困难包括:空值、特殊的NULL日期时间值(9999-12-31 24:00:00.000000)和有效日期时间值。目前的尝试中,检查DBNull值的部分有效,但在判断9999-12-31日期时引发了ArgumentOutOfRangeException错误。寻求能够正确解析这些特殊日期时间值的方法。
4550

被折叠的 条评论
为什么被折叠?



