MS Access 中的 TableAdapterManager 和相关表
我正在用 C# 编写我的第一个数据库应用程序,我必须使用 MS Access 数据库,我有两个表 Invoice 和 Order,订单表是一个子表。发票是一个父表,它具有键列“InvoiceNumber”,它是自动列,并且与订单表列“InvoiceNumber”具有一对多关系。 我在该行遇到异常
tableAdapterManager.UpdateAll(database1DataSet);
我遇到的问题是,当我尝试添加新行并单击“保存”时,
"You cannot add or change a record because a related record is required in table 'Invoice'."
,我尝试搜索,但找不到对 ms access 数据库的任何帮助,其中大多数是 SQL数据库。我还找到了一种解决方案来在数据集设计器中编辑关系以选择“关系和外键约束”选项,但它对我来说也不起作用。
谢谢
I am writing my first database application in c# and I have to use MS Access database, I have two tables Invoice and Order the order table is a child table. Invoice is a parent table it has key column "InvoiceNumber" which is auto column and it has a one to many relation with Order table column "InvoiceNumber". The problem I am having is that I got an exception at the line
tableAdapterManager.UpdateAll(database1DataSet);
when I try to add a new row and click save,
"You cannot add or change a record because a related record is required in table 'Invoice'."
I tried to search but I am unable to find it any help for ms access database, most of them are of SQL database. I also found one solution to edit the relation in the dataset designer to select the option "Both relation and foreign key constraints" but it didnot work for me either.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的 OleDbParameters 已正确设置,并且与数据库表中的列的顺序正确一致。如果在添加数据库时使用 Visual Studio 自动代码生成数据源,然后将表拖放到窗体上,请查看
DataSet.Designer.cs
文件。它会教你所有你需要知道的事情。Make sure that your OleDbParameters are properly set and in the correct corresponding order as the columns in the tables in the database. If you use Visual Studio automated code generation for data sources when you add a database, then drag and drop a table onto a form, check out the
<database name>DataSet.Designer.cs
file. It will teach you all you need to know.