youtube The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated. code example

Example: {"The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.\r\nThe statement has been terminated."}

One of the common error people face, when they use Entity Framework, is the exception "The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value." thrown. This occurs when the entity associated with the table being saved has a mandatory datetime field and you do not set it with some value. The default datetime object is created with a value of 01/01/1000 and will be used in place of null. This will be moved into the datetime field which can hold date value 1753-01-01 00:00:00 and not less than this leads to out-of-range exception. This error can be resolved by either making the datetime field to accept null or by initializing the field with a value.

Tags:

Misc Example