Prageeth godage
Prageeth godage

Reputation: 4544

keep date time null values in the database as it is when I want to change other columns in that row.

When I retrive a database result using linq,I saw that my date time is {01/Jan/0001 12:00:00 AM} when that column in database is null.And my problem is when I want to edit some other colums in that table then give me an error cannot insert the {01/Jan/0001 12:00:00 AM} value to the database.but I don't want to change that column.

can any one suggests me a method that how to keep null value as it is, when I don't want to change the that recode in the database.I know this is common scenario.

(and another not for me as a developer I not allow to change the database.)

Upvotes: 0

Views: 184

Answers (2)

Andrej B.
Andrej B.

Reputation: 170

Looks like you are using DateTime type to map your database values, but DateTime is non-nullable value type. Use DateTime? instead of DateTime

Upvotes: 1

Daniel B
Daniel B

Reputation: 8879

DateTime is a value type object which mean that you cannot set it's value to null.

Use the DBNull.Value to assign the data.


Value Types

Upvotes: 0

Related Questions