php odbc判断纪录null,C#ODBCDataReader读取空数据和空日期值(C# ODBCDataReader reading null data and null date values...

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

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.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值