【问题标题】:( {"An error occurred while updating the entries. See the inner exception for details."} )({“更新条目时发生错误。有关详细信息,请参阅内部异常。”})
【发布时间】:2016-11-08 05:20:11
【问题描述】:

每次我运行程序时,db.SaveChanges() 都会出现错误!请问,谁能帮忙解决一下?

    [HttpPost]
    public ActionResult Create(HttpPostedFileBase picture, form _form)
    {
        try
        {
            string ImageName = Path.GetFileName(picture.FileName);
            string physicalPath = Server.MapPath("~/images/" + ImageName);
            picture.SaveAs(physicalPath);

            form new1 = new form();
            new1.Name = _form.Name;
            new1.Email = _form.Email;
            new1.Phone = _form.Phone;
            //.......saving picture url......
            new1.DataImage = physicalPath;
            //Assign for remaining feilds in table in this way.

            db.forms.Add(new1);
            db.SaveChanges();
        }
        catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
        {
            Exception raise = dbEx;
            foreach (var validationErrors in dbEx.EntityValidationErrors)
            {
                foreach (var validationError in validationErrors.ValidationErrors)
                {
                    string message = string.Format("{0}:{1}",
                        validationErrors.Entry.Entity.ToString(),
                        validationError.ErrorMessage);
                    // raise a new exception nesting
                    // the current instance as InnerException
                    raise = new InvalidOperationException(message, raise);
                }
            }
            throw raise;
        }
        return View();
    }
}

【问题讨论】:

  • 每次我运行程序时,db.SaveChanges() 都会出现错误! ......请任何人都可以提供解决方案?

标签: c# asp.net-mvc-5


【解决方案1】:

您的 Form 对象中可能有空值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多