SaveChange后刷新数据源不起作用

发布于 2024-11-17 18:22:15 字数 615 浏览 14 评论 0原文

我在 ObjectSet 中添加数据,并在 ObjectContext 上执行 SaveChanges。但是新数据没有显示在DataGrid中!

代码: <代码>

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:解决方案

<代码>

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

棒棒糖 2024-11-24 18:22:15

我希望这段代码对您有所帮助。
<代码>

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

}

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

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文