Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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];

getting: Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DBNull' and 'System.DateTime?'

any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
234 views
Welcome To Ask or Share your Answers For Others

1 Answer

I suspect you meant:

form._date101 = reader[52] == DBNull.Value ? null : (DateTime?)reader[52];

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...