从 DataTableAdapter 插入未反映在 MS Access 数据库中!

发布于 2024-10-31 06:50:13 字数 1363 浏览 1 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷弦 2024-11-07 06:50:13

虽然这不是一个真正的问题,但解决方案是:

调试时修改的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文