null DateTime - "SqlDateTime overflow. Must be between.."
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:
Code:
+ [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
Re: null DateTime - "SqlDateTime overflow. Must be between.."
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>).
Re: null DateTime - "SqlDateTime overflow. Must be between.."
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
Re: null DateTime - "SqlDateTime overflow. Must be between.."
When you are using your SqlDataReader check for DB NULL first.
Code:
SqlDataReader rdr = dbConnection.ExecuteReader(sqlCmd)
DateTime myDate = rdr.IsDBNull( 0 ) ? DateTime.MinValue : rdr.GetDateTime( 0 );