Click to See Complete Forum and Search --> : null DateTime - "SqlDateTime overflow. Must be between.."


THY02K
January 27th, 2009, 12:30 AM
hello

I ran into a problem with NHibernate - "LastUpdate" field of my class defaults to null (NULL is declared in database table schema as well) but when inserted into NHibernate I got error:

+ [System.Data.SqlTypes.SqlTypeException] {"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."} System.Data.SqlTypes.SqlTypeException

I want to avoid hardcoding "NULL" to 1JAN1753 - any alternatives? Thanks

boudino
January 27th, 2009, 01:28 AM
If you are using just a DateTime as type of LastUpdate, it cannot have a null value, because it is a value type, even if you have not assigned one. And the default value, which is {1.1.0001 0:00:00}, is out of range of the SqlDateTime. Try tu use DateTime? (equivalent to Nullable<DateTime>).

MadArtSoft
January 28th, 2009, 05:45 AM
What about Framework 3.0 and 3.5 ?? Is there tha same problem with DateTime and nulls ?

www.madartsoft.com C# controls, Help Desk Software

Tron
February 2nd, 2009, 11:00 AM
When you are using your SqlDataReader check for DB NULL first.


SqlDataReader rdr = dbConnection.ExecuteReader(sqlCmd)

DateTime myDate = rdr.IsDBNull( 0 ) ? DateTime.MinValue : rdr.GetDateTime( 0 );