Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - SqlDateTime overflow. Must be between 1/1/1753 12:... ADO.NET EntityFramework

 
Thread Tools Search this Thread
Old 11-05-2009, 03:39 PM   #1
Default SqlDateTime overflow. Must be between 1/1/1753 12:... ADO.NET EntityFramework


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(bdSu bCatergories);
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


Deshi
  Reply With Quote
Old 11-05-2009, 04:26 PM   #2
Andrew Morton
 
Posts: n/a
Default Re: SqlDateTime overflow. Must be between 1/1/1753 12:... ADO.NET Entity Framework
Deshi wrote:
> 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" .


It seems unlikely that DateTime.Now would be outside the acceptable range. I
don't know where in your code the actual SQL parameters are set up, but I
check the value that's going to be added against the limits like this:

sqlParam = New SqlParameter("@DateTaken", SqlDbType.DateTime)
If reader.DateTaken >= CType(SqlDateTime.MinValue, DateTime) AndAlso
(reader.DateTaken <= CType(SqlDateTime.MaxValue, DateTime)) Then
sqlParam.Value = reader.DateTaken
Else
sqlParam.Value = DBNull.Value
End If
sqlcmd.Parameters.Add(sqlParam)

(where reader is a class which extracts exif data from a jpeg file and
DateTaken in the sql table allows nulls).

Andrew




Andrew Morton
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Computer Security aldrich.chappel.com.use@gmail.com A+ Certification 0 11-27-2007 02:11 AM
Computer Security alan.densky.com.use@gmail.com Computer Information 0 11-16-2007 02:48 AM
SYMANTEC SECURITY ADVISORIES sam1967@hetnet.nl Computer Security 2 02-14-2004 06:07 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46