views:

22

answers:

1

Hello I have an Entity "Candidate" which is set as a datasource for a GridView and a combobox. When i Update or Delete something, thw datasource is updated and the gridview and combobox show the changes.

However when i inser a new Entity then the data in the two controls doesnt refresh automatically. i have to close and reopen the form to see the changes.

My code is

AMSEntities objContext =new AMSEntities ();

private void btnInsert_Click(object sender, EventArgs e)

{

Candidate cand1 = new Candidate();

cand1.CandidateName ="Amir";

cand1.CandidateFatherName ="Asdf";

cand1.DOB =DateTime.Now;

objContext.Candidates.AddObject(cand1);

objContext.SaveChanges();

}

A: 

Not sure this is an Entity Framework question - seems to be more of an ASP.NET related question. Shouldn't you call gridView.DataBind() after SaveChanges?

Yakimych
No the application is desktop based and you dont have DataBind() for a DataGridView in winforms and the delete and update method work perfectly well using same techique. here(for insert) i have to reinitialize the Context Object i.e objContext =new AMSEntities ();
Malik Hasan