SQLDataReader null至日期时间 [英] SQLDataReader Null to datetime
本文介绍了SQLDataReader null至日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从值是null的阅读器投射日期时间时遇到问题.
Having an issue with casting a datetime from a reader where the value is null.
form._date101 = reader[52] == DBNull.Value ? DBNull.Value : (DateTime?)reader[52];
获取:由于'System.DBNull'和'System.DateTime?'之间没有隐式转换,因此无法确定条件表达式的类型
getting: Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DBNull' and 'System.DateTime?'
有什么想法吗?
推荐答案
我怀疑您的意思是
form._date101 = reader[52] == DBNull.Value ? null : (DateTime?)reader[52];
假设 _date101
是 DateTime?
类型的字段.我希望您想说如果数据库中的值为null,请使用 DateTime?
的null值;否则请使用非null的值.
That's assuming that _date101
is a field of type DateTime?
. I expect you want to say "Use the null value of DateTime?
if the value was null in the database; otherwise use the non-null value.
这篇关于SQLDataReader null至日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文