CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2001
    Posts
    872

    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

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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.

  3. #3
    Join Date
    Jan 2009
    Posts
    6

    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

  4. #4
    Join Date
    May 2002
    Posts
    511

    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
  •  





Click Here to Expand Forum to Full Width

Featured