How to properly commit bindingSource changes to source DB?(如何正确提交 bindingSource 更改到源数据库?)
问题描述
我设置了 DataGridView 和其他 UI 组件以允许用户编辑 SQLite DB 中的数据.但是这些更改(即使它们在应用程序中正确显示)不会保存到数据库中.我试过这段代码
I setup DataGridView and other UI components to allow user to edit data from SQLite DB. But these changes (even they are properly shows in application) doesn't saves to DB. I have tried this code
aBindingSource.EndEdit();
dbDataSetA.GetChanges();
aTableAdapter.Update(dbDataSetA.Accounts);
但是有并发异常:
System.Data.DBConcurrencyException 未处理 Message=Concurrency违规:UpdateCommand 影响了预期的 1 条记录中的 0 条.
System.Data.DBConcurrencyException was unhandled Message=Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
那么,伙计们,我应该如何将 bindingsource 更改提交到 DB?
So how should I commit bindingsource changes to DB, guys?
后编辑我在启动程序时遇到了这个异常,然后单击 DataGridView 中的第二行,然后单击第三行,这次程序引发了并发异常.希望他的帮助能更详细地解决这个问题.
POST EDIT I got this exception when I start the program, then click on second row in DataGridView and then on third and this time program raise a concurrency exception. Hope his help get this issue more detailed.
提前谢谢各位!
推荐答案
遇到了同样的问题.诀窍是,一旦你更新表,你应该清空"GetChanges()
.您可以通过调用方法 AcceptChanges()
来做到这一点.所以...
Had the same problem. Trick is, once you update table, you should "empty" GetChanges()
. You do that by calling method AcceptChanges()
. So...
aBindingSource.EndEdit();
dbDataSetA.GetChanges();
aTableAdapter.Update(dbDataSetA.Accounts);
dbDataSetA.AcceptChanges();
只要是同样的问题,它应该可以工作.
It should work, provided it is the same problem.
这篇关于如何正确提交 bindingSource 更改到源数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何正确提交 bindingSource 更改到源数据库?


- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01