Click here to Skip to main content
13,257,666 members (79,724 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have Updated the code,In which I am getting current date time when I click on the "Create New" it fills the field of CheckInTime Automatically and when I click on edit It fills the Checkout field for me but when I click on the save button It arose an Exception"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."what should I do to handle the Exception.Kindly Reply.
Thank you.

public ActionResult Create()
           EmployeeContext empDB = new EmployeeContext();
           Employee emp = new Employee();
           var emp1 = new Employee()
               CheckInTime = DateTime.Now


           return View(emp1);

 public ActionResult Edit(int id)
            Employee employee = db.Employees.Find(id);
            if (employee.CheckOutTime == null)
                var emp2 = new Employee();
                    emp2.CheckOutTime = DateTime.Now;
                return View(emp2);
            return View(employee.CheckOutTime);
        // POST: /Employee/Edit/5
        public ActionResult Edit(Employee employee)
            Employee em = new Employee();
            if (ModelState.IsValid)
                db.Entry(employee).State = EntityState.Modified;
                return RedirectToAction("Index");
            return View(employee.CheckOutTime=System.DateTime.Today);
        // GET: /Employee/Delete/5
        public ActionResult Delete(int id)
            Employee employee = db.Employees.Find(id);
            return View(employee);
Posted 26-Feb-12 4:41am
Updated 27-Feb-12 4:34am
M Ali Qadir 28-Feb-12 8:40am
Please reply to this post thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171114.1 | Last Updated 27 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100