Click here to Skip to main content
15,867,780 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code

Additional information: An error occurred while updating the entries. See the inner exception for details.

This is the error i receive..

code is ::

C#
var sm = new SupplierMaster();
         //  var add = new Address();

            if (ModelState.IsValid)
            {
                sm.SupplierId = ic.SupplierId;
                sm.SupplierName = ic.SupplierName;
                sm.SupplierPhone = ic.SupplierPhone;

                sm.KeyId = ic.KeyId;
                sm.UserId = ic.UserId;
                sm.createdDate = DateTime.Now;
                sm.CreatedBy = ic.UserId;
                sm.UpdatedBy = ic.UserId;
                sm.UpdatedDate = DateTime.Now;
                sm.Address1= ic.Address1;
                sm.AddType = ic.AddType;
                sm.City = ic.City;
                sm.State = ic.State;
                sm.Zip = ic.Zip;

                be.SupplierMasters.Add(sm);
                be.SaveChanges();

                ViewBag.Address = new SelectList(be.Addresses, "Address", "AddType", sm.Address);
                ViewBag.Address = new SelectList(be.Addresses, "Address", "Address1", sm.Address);
                ViewBag.Address = new SelectList(be.Addresses, "Address", "State", sm.Address);
                ViewBag.Address = new SelectList(be.Addresses, "Address", "City", sm.Address);
                ViewBag.KeyId = new SelectList(be.Addresses, "KeyId", "Address", sm.KeyId);
                ViewBag.UserId = new SelectList(be.LoginUsers, "UserId", "UserName", sm.UserId);
                ViewBag.CreatedBy = new SelectList(be.LoginUsers, "UserId", "UserName", sm.CreatedBy);
                ViewBag.UpdatedBy = new SelectList(be.LoginUsers, "UserId", "UserName", sm.UpdatedBy);
                return RedirectToAction("SupplierMaster", "Supplier");
Posted
Updated 13-Mar-18 2:21am
Comments
[no name] 14-May-14 6:13am    
please mention your model class or the relationships between the columns of the tables.

1 solution

As Per my understanding..check the below things

1. Have you set any primary key for the table which you created, if so set identity column.

2. Once its done, we need to Refresh Entity Framework Model After Database Change


Hope this solution works.
 
Share this answer
 

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