Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a confution in my project that when I am modifying the data to db it shows the error that "
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions."

I am getting the value which I needed in the HttpPost of edit action method, the error arise only when saving it to the db
controller
[HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Edit( StudentDetail studentDetail )
        {
            if (ModelState.IsValid)
            {
                studentDetail .CashInHand -= studentDetail .CashReceived;
                studentDetail .Amount += studentDetail .CashReceived;
                studentDetail .Date = DateTime.Now;
                studentDetail .CashReceived= null;

                db.Entry(studentDetail ).State = EntityState.Modified;
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }
            return View(studentDetail );
        }


I am getting details in studentDetail. Then Why is that the error showing ???can anyone please help me to find the solution ??

What I have tried:

I have search the my error but i didn't understand why is that happening Can anyone please help me to find the solution ??
Posted
Updated 10-May-17 0:36am

1 solution

 
Share this answer
 
v2

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