Reputation: 559
I add data in an ObjectSet
and did SaveChanges
on ObjectContext
. But the new data does not shown in the DataGrid
!
Code:
How to refresh data or view new data?
bsWork.DataSource = Program.EC.Addresses;
...
Address newAdr = new Address();
//change properties newAdr
...
Program.EC.Addresses.AddObject(newAdr);
Program.EC.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
...
bsWork.Add(newAdr);
Program.EC.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
...
Upvotes: 2
Views: 986
Reputation: 442
I hope this code may helpful for you.
try {
// Try to save changes, which may cause a conflict.
int num = context.SaveChanges();
Console.WriteLine("No conflicts. " + num.ToString() + " updates saved.");
}
catch (OptimisticConcurrencyException) {
// Resolve the concurrency conflict by refreshing the
// object context before re-saving changes.
context.Refresh(RefreshMode.ClientWins, orders);
// Save changes.
context.SaveChanges();
Console.WriteLine("OptimisticConcurrencyException "
+ "handled and changes saved");
}
Upvotes: 1