如何解析Nullable< DateTime>从SqlDataReader [英] How to parse Nullable<DateTime> from a SqlDataReader
本文介绍了如何解析Nullable< DateTime>从SqlDataReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DateTime.TryParse方法采用DateTime作为参数,而不是DateTime??
The DateTime.TryParse method takes a DateTime as an argument, not a DateTime? ?
现在我有以下代码:
if(!DateTime.TryParse(reader["Placed"].ToString(), out _placed)){
throw new Exception("Order's placed datetime could not be parsed.");
}
_placed的类型
where _placed is of type
Nullable<DateTime> _placed = null;
如何解决?
推荐答案
相反呢?
int x = reader.GetOrdinal("Placed");
if(!reader.IsDBNull(x))
_placed = reader.GetDateTime(x);
这篇关于如何解析Nullable< DateTime>从SqlDataReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文