开发者

Reading a datetime column with a null data SqlCeDataReader?

开发者 https://www.devze.com 2023-01-19 13:36 出处:网络
What\'s the way to read a column that mig开发者_如何学编程ht have a null datetime value in SQLCe?

What's the way to read a column that mig开发者_如何学编程ht have a null datetime value in SQLCe?

Right now i have this

SqlCeDataReader reader = cmd.ExecuteReader();
DateTime? shapeFileSQLDateTime = (DateTime?)reader["ShapeFileTimestamp"];//ok b/c has data
DateTime? mdbSQLDateTime = (DateTime?)reader["CreatedTimestamp"];  //throws exception b/c is null data in cell

I can wrap it in an exception handler, but I don't want to.

I'm using C# and vs2010


Try this:

DateTime? mdbSQLDateTime = reader["CreatedTimestamp"] == DBNull.Value ? null : (DateTime?)reader["CreatedTimestamp"]


DateTime? mdbSQLDateTime =  reader["CreatedTimestamp"] == null ? null :  (DateTime?)reader["CreatedTimestamp"];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号