如何使用Sql server自动生成的ID列更新与一对多关系的dataSet表 [英] how to update dataSet tables with one to many relationship with Sql server autogenerated ID columns

查看:91
本文介绍了如何使用Sql server自动生成的ID列更新与一对多关系的dataSet表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据集中有3个表

dtPurchase,dtPurchaseProduct和dtPurchaseProductExp



dtPurchase是dtPurchaseProduct的父表,dtPurchaseProduct是父表of dtPurchaseProductExp。



i想分别将这些行插入数据库中。



所有主键列都是sql server autogenerated id columns。

解决方案

插入第一个表并使用 SCOPE_IDENTITY 将返回您当前范围内最后生成的标识值。



  SELECT   SCOPE_IDENTITY   AS  NewID 


i have 3 tables in data set
dtPurchase, dtPurchaseProduct and dtPurchaseProductExp

dtPurchase is parent table of dtPurchaseProduct and dtPurchaseProduct is parent table of dtPurchaseProductExp.

i want to insert these rows to database talbes respectively.

all primary key columns are sql server autogenerated id columns.

解决方案

Insert into first table and get its primary key using SCOPE_IDENTITY which will return you the last generated identity value within your current scope.

SELECT SCOPE_IDENTITY AS NewID


这篇关于如何使用Sql server自动生成的ID列更新与一对多关系的dataSet表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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