如何将第一个数据表中的主键值传递到第二个数据表中的外键 [英] How Do I Pass The Primary Key Value In 1St Data Table To Foreign Key In The Second Data Table

查看:139
本文介绍了如何将第一个数据表中的主键值传递到第二个数据表中的外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张桌子,比如

Emp和Order



在Emp表中:

Eid int pk ,

EName varchar(50),

EAddress varchar(50)。



和In Order表:

Oid int pk

OProduct varchar(50),

Eid int fk





现在我有两个页面,如Emp.aspx和Products.aspx



所以现在我想将值插入两个页面将Same Eid pk(Emp.aspx)值传递给(Products.aspx)中的Eid fk ...

请帮助我如何将值从一个页面传递到另一个页面而不会错过值





先谢谢

I have two tables like
Emp and Order

In Emp table:
Eid int pk,
EName varchar(50),
EAddress varchar(50).

and In Order table:
Oid int pk
OProduct varchar(50),
Eid int fk


Now i have two page like Emp.aspx and Products.aspx

So now i want to insert the value to both pages by passing Same Eid pk(Emp.aspx) value to Eid fk in (Products.aspx)...
Please help me how to pass the value from one page to another without missing the value


Thanks in Advance

推荐答案

首先创建一个交易。 />
然后插入主表行。

然后使用 @ @IDENTITY [ ^ ]插入第二个表值。

执行交易。



执行此操作的具体步骤取决于你在哪里:在你的C#代码中或通过SQL存储过程(每个方法都有它的拥护者)。
Start by creating a Transaction.
Then insert the primary table row.
Then use @@IDENTITY[^] to insert the second table values.
COMMIT the transaction.

The exact procedure for doing this depends on where you are doing it: in your C# code or via an SQL stored procedure (Each method has its adherents).


参考:如何:在ASP.NET Web窗体页面之间传递值 [ ^ ]


这篇关于如何将第一个数据表中的主键值传递到第二个数据表中的外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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