Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
C#
using (var dbCtx = new EmployeeEntities())
        {
            //Mark entity as modified
            dbCtx.Entry(stud).State = System.Data.EntityState.Modified;
            dbCtx.SaveChanges();
        }

If am set property "Entry" in Entitties then display error.
So i have not any idea ..
How Display Error.

C#
private void Save()
    {

        EmployeeMast objEmp = new EmployeeMast();

        objEmp.EmpName = txtName.Text.Trim();
        objEmp.EmpAdd = txtAddress.Text.Trim();
        // objEmp.EmpBDate = Convert.ToDateTime(txtBDay.Text.Trim());
        objEmp.EmpDept = Convert.ToInt32(drpDepartment.SelectedValue);

        if (ViewState["EmpId"] == null)
        {
            obj.EmployeeMasts.AddObject(objEmp);
            obj.SaveChanges();
        }
        else
        {
            objEmp.EmpId = 1;
            obj.Entry(objEmp).State = System.Data.EntityState.Modified;
            obj.SaveChanges();
        }
    }
if i am update record then write code this line.

obj.Entry(objEmp).State = System.Data.EntityState.Modified;
then "Entry" not set ..Error display.
Posted
Updated 28-Dec-13 6:11am
v2
Comments
JoCodes 28-Dec-13 9:54am    
Can you make it more clear????
Abhai Oza 28-Dec-13 10:05am    
i am update record using entity freamwork.
i am this code.
private void Save()
{

EmployeeMast objEmp = new EmployeeMast();

objEmp.EmpName = txtName.Text.Trim();
objEmp.EmpAdd = txtAddress.Text.Trim();
// objEmp.EmpBDate = Convert.ToDateTime(txtBDay.Text.Trim());
objEmp.EmpDept = Convert.ToInt32(drpDepartment.SelectedValue);

if (ViewState["EmpId"] == null)
{
obj.EmployeeMasts.AddObject(objEmp);
obj.SaveChanges();
}
else
{
objEmp.EmpId = 1;
obj.Entry(objEmp).State = System.Data.EntityState.Modified;
obj.SaveChanges();
}
}
if i am update record then write code this line.

obj.Entry(objEmp).State = System.Data.EntityState.Modified;
then "Entry" not set ..Error display.
JoCodes 28-Dec-13 10:13am    
If its Editing you need to display an alert or something like that???
Abhai Oza 28-Dec-13 10:20am    
Yes... How to update record using EF.
if i am using this line update record..but Entry not set..Error display.

EmployeeEntities obj = new EmployeeEntities();
EmployeeMast objEmp = new EmployeeMast();
obj.Entry(objEmp).State = System.Data.EntityState.Modified;

Give me any Idea. How to update record using EF.
JoCodes 28-Dec-13 10:28am    
Sorry not able to get you clearly. The code posted is to update the modified objModel to your db table .But entry not set? can you explain that? Are you getting errors?

1 solution

On edit section you have to attach the modified object is as below.

obj.EmployeeMasts.Attach(objEmp);


For more info : How to update using Entity Framework
 
Share this answer
 

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