SqlDateTime overflow. Must be between 1/1/1753 12:00:00... ADO.NET Entity Framework

118 views
Skip to first unread message

Deshi

unread,
Nov 5, 2009, 10:37:35 AM11/5/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

This strange error bugs me lot.... This is very strage, I'm trying to
insert data into the table through ADO.NET Entity Framework.. nothing
seems to work my way.. i've been getting error "SqlDateTime overflow.
Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM" .

here is my code

DirectoryEntities bdEntities = new DirectoryEntities();


Directory_SubCategory bdSubCatergories = new Directory_SubCategory();
Directory_Category categoryObject = new Directory_Category();
bdSubCatergories.Directory_Category = categoryObject;
bdSubCatergories.SubCategoryName = masterParams[0];
bdSubCatergories.Directory_Category.CategoryID = Convert.ToInt32
(masterParams[1]);
bdSubCatergories.CreatedBy = Convert.ToInt32(masterParams[2]);
bdSubCatergories.CreatedDate = DateTime.Now; ///This could be
source of error
bdSubCatergories.ModifiedDate = DateTime.Now;
bdEntities.AddToBusinessDirectory_SubCategory(bdSubCatergories);
bdEntities.SaveChanges(true); //It throws me exception here

All my previous database insertions are happening perfectly. in this
case i'm getting strange exception. reason could be i'm mapping two
table to update.. does anyone had this kind of error

rbr

unread,
Nov 6, 2009, 12:04:00 PM11/6/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Deshi,

It appears that you have another field that is being inserted that is
a DateTime format that is not getting set in your code. This error
occurs when you are inserting a DateTime record that is set to .NET
DateTime.MinValue. (Which the runtime defaults to if it is not set.)
If you could find this value and set it, or default the value to
SqlDateTime.MinValue.

Alternatively, I would recommend possibly letting the database set the
values for a CreateDate (on insert trigger) and LastUpdate (on insert
and update) field. This eliminates the need to set these values in the
code.

Best.

rbr
Reply all
Reply to author
Forward
0 new messages