将数据插入C#数据集 [英] Inserting data into C# Datasets

查看:105
本文介绍了将数据插入C#数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案
  

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

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

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

  3. 阅读最新值从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.

解决方案

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.

  1. 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.

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

  3. 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.

这篇关于将数据插入C#数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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