0

I have a query to update a record in the database. But when I execute it I get an exception saying,

'System.Data.Entity.Infrastructure.DbUpdateException'

When I view details, it says "An error occurred while updating the entries. See the inner exception for details" I have tried many solutions found in the internet. But none of them worked for me.
Here is my code in controller

[HttpPost]
public JsonResult saveChanges(person person1)
{
        person _person = new person();
        _person.SID = person1.SID;
        _person.email = person1.email;
        _person.password = Crypto.HashPassword(person1.password);
        Session["_person"] = _person;

        string sessionValue = Session["userID"].ToString();
        bool status;
        if (!ModelState.IsValid) return Json(false, JsonRequestBehavior.AllowGet);
        status = repo.updatePerson(sessionValue,_person);

        return Json(status, JsonRequestBehavior.AllowGet);

}         

Code in repository class

 public bool updatePerson(string ID,person _objPerson)
 {
      person temp = null;
      temp = (from p in _dbContext.people
                    where p.SID == ID
                    select p).SingleOrDefault();
            temp.FirstName = _objPerson.FirstName;
            temp.LastName = _objPerson.LastName;
            temp.password = _objPerson.password;
            temp.DOB = _objPerson.DOB;
            temp.email = _objPerson.email;
            //_dbContext.SaveChanges();
            //Guid id = _objPerson.Person_ID;
            if (_dbContext.SaveChanges() > 0)
            {
                 return true;
            }
            return false;
7
  • 1
    "See the inner exception for details" - What does it tell you about the error?
    – user3559349
    Dec 12, 2016 at 6:42
  • How do I check the inner exception?
    – Mike
    Dec 12, 2016 at 6:44
  • Debug your code :) - View detail ...
    – user3559349
    Dec 12, 2016 at 6:47
  • I tried using this code. string msg = (e.InnerException.Message); It also give the message as "An error occurred while updating the entries. See the inner exception for details."
    – Mike
    Dec 12, 2016 at 6:52
  • 1
    One of your person table fields only allows data of a certain length are you passing it a value which is longer than allowed
    – user3559349
    Dec 12, 2016 at 6:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.