patrick
patrick

Reputation: 16979

Reading a datetime column with a null data SqlCeDataReader?

What's the way to read a column that might 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

Upvotes: 1

Views: 715

Answers (2)

Roadie57
Roadie57

Reputation: 324

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

Upvotes: 2

AdaTheDev
AdaTheDev

Reputation: 147344

Try this:

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

Upvotes: 2

Related Questions