Artem Zubkov
Artem Zubkov

Reputation: 559

Refresh DataSource after SaveChange does not work

I add data in an ObjectSet and did SaveChanges on ObjectContext. But the new data does not shown in the DataGrid!

Code:

bsWork.DataSource = Program.EC.Addresses;
...
Address newAdr = new Address();
//change properties newAdr
...
Program.EC.Addresses.AddObject(newAdr);
Program.EC.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
How to refresh data or view new data?

UPD: Solution

...
bsWork.Add(newAdr);
Program.EC.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
...

Upvotes: 2

Views: 986

Answers (1)

SuSanda
SuSanda

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

Related Questions