2

我在 an 中添加数据ObjectSetSaveChangesObjectContext. 但是新数据没有显示在DataGrid

代码:

bsWork.DataSource = Program.EC.Addresses;
...
Address newAdr = new Address();
//change properties newAdr
...
Program.EC.Addresses.AddObject(newAdr);
Program.EC.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
如何刷新数据或查看新数据?

UPD:解决方案

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

4

1 回答 1

1

我希望这段代码对你有帮助。

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");

}

于 2011-06-29T03:14:50.343 回答