TableAdapter无法保存更改 [英] TableAdapter cannot save changes
问题描述
我正在把头发拔掉.我有一个使用TableAdapter访问MDB文件的程序.直到最近为止,一切都很好.
我可以写和读该表,但是当我尝试删除特定行时,它不起作用.
I''m pulling my hair out on this one. I have a program that access a MDB file using TableAdapter. It was working fine until recently.
I am able to write and read the table but when I try to delete a specific line, it does not work.
MessageBox.Show(dataMDBDataSet.Machines.Count.ToString());
if (machinesBindingSource.AllowEdit)
{
MessageBox.Show("yes");
}
dataMDBDataSet.Machines.Rows.RemoveAt(i);
machinesBindingSource.EndEdit();
dataMDBDataSet.AcceptChanges();
machinesTableAdapter.Update(this.dataMDBDataSet.Machines);
MessageBox.Show(dataMDBDataSet.Machines.Count.ToString());
this.machinesTableAdapter.Fill(this.dataMDBDataSet.Machines);
MessageBox.Show(dataMDBDataSet.Machines.Count.ToString());
当我按Delete键时,计数下降了1.允许编辑为true.它更新没有错误.当我再次填写表格时,计数又恢复了原来的值!
我尝试了我所知道的一切.如果使用Microsoft Access 2007进行编辑,则MDB文件完全可以.我使用的是Framework 4.0.
有人可以帮忙吗?
When I press delete, the count dropped by 1. Allow edit is true. It updates without error. When I fill the table again, the count went back to original!
I tried everything I know. The MDB file is totally fine if I edit it with Microsoft Access 2007. I am using framework 4.0.
Can someone help?
推荐答案
我希望您删除主键并尝试后,您正在使用的主键.在调试应用程序时,请关闭msacess数据库.
I hope that Your Using Primary key once u delete the primary key and try.And while debugging the application please close the msacess database.
记住几个选项:
-如果(希望)您正在使用事务,请确保事务已提交并且不会回滚.
-如果您的项目中包含MDB,请检查您是否未使用bin/debug(或等效目录)目录中的文件.如果从那里使用文件,则在编译项目时它可能会被覆盖.
Few options come in mind:
- if (hopefully) you''re using transactions, ensure that the transaction gets committed and is not rolled back.
- if the MDB is included into your project, check that you''re not using the file from bin/debug (or equivalent) directory. If you use the file from there, it may get overwritten when you compile the project.
这篇关于TableAdapter无法保存更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!