Click here to Skip to main content
15,886,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
Hi,
I m fetching the problem with updating record, when I debug my project then it made those changes in data, but its not saving the updated record and showing an error on db.SaveChanges();


SQL
The error is ;
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.



Code :

      [NonAction]
privateFinancilInstituteWrappergetData(int id)
        {
FinancilInstituteWrapper temp = newFinancilInstituteWrapper();
var details = from i indb.IIDBS
join a indb.ACDBS
oni.Idequalsa.Id
join b indb.BIDBSoni.Idequalsb.Id
wherei.Id==id
selectnewFinancilInstituteWrapper
                          {
                              II = i,
                              AC = a,
                              BI = b
                          };
foreach (FinancilInstituteWrapper a in details)
            {
temp.II = a.II;
                temp.BI = a.BI;
                temp.AC = a.AC;
            }

return temp;
        }

//
// GET: /FinancilInstitute/Edit/5

publicActionResult Edit(int id=0)
        {
return View(getData(id));
         }

//
// POST: /FinancilInstitute/Edit/5

        [HttpPost]
publicActionResult Edit(FinancilInstituteWrapper wrapper)
        {
// try
// {
if (ModelState.IsValid)
                {
db.Entry(wrapper.II).State = EntityState.Modified;
db.Entry(wrapper.AC).State = EntityState.Modified;
db.Entry(wrapper.BI).State = EntityState.Modified;
try
                    {
db.SaveChanges();
                    }
catch (OptimisticConcurrencyException)
                    {

                    }
returnRedirectToAction("Index");
                }
// }
//catch
//{
return View(wrapper);
//}
        }



Can anyone help me solve this Problem….
Posted

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