从 DataTableAdapter 插入未反映在 MS Access 数据库中!
我使用 MS Access 作为我的数据库,并使用数据集来检索和更新我的 WPF 应用程序。 数据显示在数据网格中没有问题。 但是,当我尝试使用以下代码插入数据时,插入成功完成,但在 Access 文件中看不到新行。
var add = new AddressBookDataSet();
adc.Fill(add.Address);
var v = add.Address.NewAddressRow();
v.StreetAddress = textBoxStreetAddress.Text;
v.AtPost = textBoxAtPost.Text;
v.Taluka = textBoxTaluka.Text;
v.District = textBoxDistrict.Text;
v.State = textBoxState.Text;
v.Pincode = textBoxPincode.Text;
v.PhoneNumber1 = textBoxContact1.Text;
v.PhoneNumber2 = textBoxContact2.Text;
v.PhoneNumber3 = textBoxContact3.Text;
v.PhoneNumber4 = textBoxContact4.Text;
v.FaxNumber1 = textBoxFax1.Text;
v.FaxNumber2 = textBoxFax2.Text;
add.Address.AddAddressRow(v);
add.Address.AcceptChanges();
//adc.Insert(textBoxStreetAddress.Text, textBoxAtPost.Text, textBoxTaluka.Text, textBoxDistrict.Text, textBoxState.Text, textBoxPincode.Text, textBoxContact1.Text, textBoxContact2.Text, textBoxContact3.Text, textBoxContact4.Text, textBoxFax1.Text, textBoxFax2.Text);
这里可能有什么问题?我检查了 .accdb 没有标记为只读! 此处,省略了 1 个字段 v.Id,因为 Id 字段是自动编号! 另外,在创建新行之前,我尝试了 adc.Insert (即 TableAdapter.Insert),但它没有在数据库中更新!
I am using MS Access as my Database and using Dataset for retrieval and update for my WPF app.
The data is shown in a datagrid without issues.
However, when i try to insert data using the following code, the insert is completed successfully, but the new row cannot be seen in the Access file.
var add = new AddressBookDataSet();
adc.Fill(add.Address);
var v = add.Address.NewAddressRow();
v.StreetAddress = textBoxStreetAddress.Text;
v.AtPost = textBoxAtPost.Text;
v.Taluka = textBoxTaluka.Text;
v.District = textBoxDistrict.Text;
v.State = textBoxState.Text;
v.Pincode = textBoxPincode.Text;
v.PhoneNumber1 = textBoxContact1.Text;
v.PhoneNumber2 = textBoxContact2.Text;
v.PhoneNumber3 = textBoxContact3.Text;
v.PhoneNumber4 = textBoxContact4.Text;
v.FaxNumber1 = textBoxFax1.Text;
v.FaxNumber2 = textBoxFax2.Text;
add.Address.AddAddressRow(v);
add.Address.AcceptChanges();
//adc.Insert(textBoxStreetAddress.Text, textBoxAtPost.Text, textBoxTaluka.Text, textBoxDistrict.Text, textBoxState.Text, textBoxPincode.Text, textBoxContact1.Text, textBoxContact2.Text, textBoxContact3.Text, textBoxContact4.Text, textBoxFax1.Text, textBoxFax2.Text);
What could be the issue here? I checked the .accdb is not marked read-only!
here, 1 field v.Id has been ommitted as the Id field is an autonumber!
also, before going with creating a new Row, I tried the adc.Insert (i.e. TableAdapter.Insert) yet it doesn't update in the DB!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然这不是一个真正的问题,但解决方案是:
调试时修改的 Access 文件存在于 /Project/bin/debug 文件夹中,而不是位置用于存储文件!!
因此,更改在 Debug 文件夹中的 accdb 文件副本中可见。
Although this was not a real issue, yet the solution:
The Access file which gets modified while debugging is present in the /Project/bin/debug folder, and not the location used for storage of the file!!
So the changes are visible in the copy of the accdb file in the Debug folder.