如何正确地将bindingSource更改提交给源数据库? [英] How to properly commit bindingSource changes to source DB?
问题描述
aBindingSource.EndEdit();
dbDataSetA.GetChanges();
aTableAdapter.Update(dbDataSetA.Accounts);
但是有并发异常:
System.Data.DBConcurrencyException未处理Message =并发
违例:UpdateCommand影响预期1条记录的0。
那么我应该如何将绑定源更改提交给DB呢?
POST EDIT
我启动程序时收到此异常,然后单击DataGridView中的第二行,然后单击第三行,此时程序提升一个并发异常。希望他的帮助得到这个问题更详细。
提前感谢!
这样的东西?
try
{
aBindingSource.EndEdit();
dbDataSetA.GetChanges();
aTableAdapter.Update(dbDataSetA.Accounts);
}
catch(DBConcurrencyException exc)
{
MessageBox.Show(原始数据已更改,请重做更新);
aTableAdapter.Fill(dbDataSetA);
}
然后根据需要重新分配dbDataSetA作为DataSource,用户必须再次输入数据。 / p>
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);
but there are concurrency exception:
System.Data.DBConcurrencyException was unhandled Message=Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
So how should I commit bindingsource changes to DB, guys?
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.
Thanks in advance, guys!
Something like this?
try
{
aBindingSource.EndEdit();
dbDataSetA.GetChanges();
aTableAdapter.Update(dbDataSetA.Accounts);
}
catch (DBConcurrencyException exc)
{
MessageBox.Show("original data changed, please redo updates");
aTableAdapter.Fill(dbDataSetA);
}
Then reassign dbDataSetA as DataSource if needed and user has to enter data again.
这篇关于如何正确地将bindingSource更改提交给源数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!