|
-
January 27th, 2009, 01:30 AM
#1
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
-
January 27th, 2009, 02:28 AM
#2
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>).
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
-
January 28th, 2009, 06:45 AM
#3
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
-
February 2nd, 2009, 12:00 PM
#4
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 );
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|