Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hii to all,

when i want to delete a record iam finding the following Error
ERROR:-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

This Is My Controller Code:-
public ActionResult About()
{
//Employee model = new Employee();
return View();
}
[HttpPost]
public ActionResult About(Employee model)
{
using (personalEntities db = new personalEntities())
{
checkeddetail obj = new checkeddetail();
var delete = (from s in db.checkeddetails where model.searchByName == s.textname select s.empid).FirstOrDefault();
obj.empid = delete;
db.checkeddetails.Attach(obj);
db.checkeddetails.DeleteObject(obj);
db.SaveChanges();
}
return View();
}
Please guide me how should i overcome the following Error

Thanks
Ramu
Posted

1 solution

It may be because your personal identity ID(key) is missing. Check the value by putting a break point.
For more information, check this[^] thread
EDIT:
C#
public ActionResult About()
{
    //Employee model = new Employee();
    return View();
}
[HttpPost]
public ActionResult About(Employee model)
{
   using (personalEntities db = new personalEntities())
   {
      var delete = (from s in db.checkeddetails where model.searchByName == s.textname select s.empid).FirstOrDefault();
      db.checkeddetails.DeleteObject(delete);
      db.SaveChanges();
   }
   return View();
}
 
Share this answer
 
v2
Comments
Ram7 from Hyderabad 8-Jul-13 7:21am    
Hi Shanu,
Thanks for ur quick responce,ya i checked once again, whatever the ID i need is getting showing in obj,iam finding the error at db.savechanges()line of my code,
Thanks
Ramu
Shanu2rick 8-Jul-13 7:53am    
i have updated the answer with the code...
you may want to check
Ram7 from Hyderabad 8-Jul-13 8:17am    
Hi Thanku again,nw its working fine..............

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