Click here to Skip to main content
15,860,943 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everybody,I got an error when I was trying to updating the data in the database in my 1st ASP.Net MVC application and the error is "
An error occurred while updating the entries. See the InnerException for details.
So please help me to solve out my this problem.Here's below is the code:

SQL
public ActionResult Create()
  {
      return View();
  }
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="Id")] Movie movieToCreate)
  {
      if (!ModelState.IsValid)
          return View();

      _db.AddToMovies(movieToCreate);
      _db.SaveChanges();  //Error Line

      return RedirectToAction(movieToCreate);
     }
Posted
Updated 9-Jun-20 9:30am
Comments
Rob Philpott 19-Dec-14 4:44am    
First look at the inner exception. When the exception is raised in VS, click 'View Detail' and that should tell you what the problem is.
AnoopGharu 19-Dec-14 5:04am    
I check it Sir & but when I trying to update the values it again showing the same error "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."
Rob Philpott 19-Dec-14 5:18am    
Almost certainly you'll have DateTime.MinValue (Jan 1st 0001). SQL server can't store this because as stated it can only store dates from 1753 onwards.
AnoopGharu 19-Dec-14 5:23am    
Can you please help me what I need to write in my application to store into the database table, because I am new to ASP.Net MVC.
Jameel VM 19-Dec-14 4:51am    
what is the inner exception?

If you have any DateTime property in Movie class please initialize with current DateTime like below before save

C#
movieToCreate.DateProperty=DateTime.Now;
_db.AddToMovies(movieToCreate);
_db.SaveChanges();

Hope this helps
 
Share this answer
 
Comments
AnoopGharu 19-Dec-14 6:40am    
Thank you Sir, now I got it.Can you explain me in little detail why I have to need to initialize this DateTime Property.
Sinisa Hajnal 19-Dec-14 7:30am    
Because database cannot accept date value before year 1783 and default value for your code is year 0001...you don't have to initialize it to NOW. It depends on your needs. You could initialize it to 1.1.3000 to signify that nobody entered any "real" value. And if your app is still active after 986 years when this becomes relevant BRAVO :) Y3K bug
Jameel VM 20-Dec-14 2:21am    
Nice answer..
please check all column there have some column not allow null.
In my case column [ID] not allow null, so you need to give value for it.
 
Share this answer
 
Comments
CHill60 10-Jun-20 5:28am    
No - just check the datetime columns - the error was "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."
You've added nothing of value over what was said in Solution 1 5 years ago

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900