how to update selected record in EF

  • Thread starter Thread starter zleug
  • Start date Start date
Z

zleug

Guest
Hi All.

In my DataGrid each row has button to modify according record. The method that I created try to update first record

public static int UpdateEmployee(EmployeeDT employee)
{
try
{
int result = 0;
using (var context = new Model1())
{
var emp = context.Employees.FirstOrDefault<Employee>();

emp.EmployeelId = employee.EmployeeId;
emp.Name = employee.Name;
emp.Depatrment = employee.Department;
emp.IsActive = employee.IsActive;
emp.UpdatedDate = employee.UpdatedDate;
emp.UpdatedBy = employee.UpdatedBy;

context.Entry(employee).State = EntityState.Modified;
context.SaveChanges();
}
return result;
}
catch (Exception ex)
{
throw new Exception("The data did not updated." + ex.ToString());
}
}


I would like to modify record where was clicked Edit button. How to change code of the method to modify selected record?

Thanks

Continue reading...
 
Back
Top