在C#和表格中保存问题 [英] Saving problem in C# and tables

查看:95
本文介绍了在C#和表格中保存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Access中有两个表,带主键的表1和带外键的表2.
我在C#中创建了一个WIn表单.将两个表都拖到带有详细信息的表单中. table2出现在table1的底部.使用BindingNavigator,我创建了一个新的空表格.输入数据,然后尝试将数据保存到表1和2中.它保存在表1中,但不保存在表2中.实际上,当我单击保存"按钮时,它会删除与table2

I have two tables in Access, table1 with Primary key and table2 with foreign key.
I Created a WIn form in C#. Drag both tables into forms with details. table2 as a it appears at the bottom of table1. Using BindingNavigator i created a new empty form. Enter data and try to save the data into table 1 & 2. It Saves in table1 BUT not in table2. In fact when I click save button, it erases the content of all controls related to table2

推荐答案

拖放控件将不会为您执行此操作. br/>
您必须添加代码以自己将数据保存到table2中.您将数据写入table1,获取新添加记录的主键值,然后使用table1中的键值作为外键将数据写入table2.

您可以在此处 [
The drag and drop contorl won''t do this for you.

You have to add the code to save the data to table2 yourself. You''d write the data to table1, get the primary key value of the newly added record, then write the data to table2, using the key value from table1 as the foreign key.

You can find an example of doing that here[^].


这篇关于在C#和表格中保存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆