将数据插入C#数据集数据

2023-09-06 14:41:20 作者:再見小時候

我正在使用中,我创建了一个dataset.Now我想创建一个方法,我将在一个表中输入记录,这将通过返回一个值即小学key.Now C#.NET应用程序的主键我必须在5表插入记录,我必须使用该主键的外键,使用该数据集5席。

解决方案   

你需要告诉你的父表的表适配器刷新   更新操作后的数据表。   这是你如何能做到这一点。

打开 ParentTableAdapter属性 - >默认选择查询 - > Advnaced选项。并检查刷新数据表的选项。现在保存适配器。现在,当你调用表适配器更新,在数据表将被更新[刷新]更新操作后,将反映数据库表中的最新值。 如果主键或任何coloumn设置为自动递增,数据表将有那些最新的岗位价值最新的更新。

现在,你可以调用更新为ParentTableAdapterObj.Update(ds.dataTable);

阅读最新值从ParentDataTable(ds.dataTable)coloumns和更新之前指定的相应值到子表。这将工作正是你想要的方式。

I am using C#.Net application in which i created a dataset.Now i want to create a method in which i will enter a record in one table which will return a value ie primary key.Now by using that primary key i have to insert records in 5 tables and i have to use that primary key as a foreign key for this 5 tables using dataset.

解决方案 如何把vc里生成的数据导入到mysql数据库

You need to tell your parent table's table-adapter to refresh the data-table after update operation. This is how you can do that.

Open the properties of ParentTableAdapter -> Default Select Query -> Advnaced options. and Check the option of Refresh the data table. Save the adapter now. Now when you call update on table-adapter, the data-table will be updated [refreshed] after the update operation and will reflect the latest values from database table. if the primary-key or any coloumn is set to auto-increment, the data-table will have those latest value post recent update.

Now you can Call the update as ParentTableAdapterObj.Update(ds.dataTable);

Read latest values from the ParentDataTable(ds.dataTable) coloumns and assign respective values into the child table before update. This will work exactly the way you want.