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 更改到源数据库?
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
