如何在插入时间过程中获取任何表的Id [英] How to get Id of any table at the Time of Insert procedure

查看:89
本文介绍了如何在插入时间过程中获取任何表的Id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用帮助插入程序的返回值获取表格的ID

以及如何在asp.net网页中显示此值。



How to get Id of table with the help insert procedure's return value
and how to show this value in asp.net web page.

create proc usp_ins_PaymentRcv
@id int OUTPUT,
@cid int,
@Amt int
as
Insert into PaymentRcv (CrFromCid,Amt) values (@cid,@Amt)
SET @ID=SCOPE_IDENTITY()
RETURN @ID

推荐答案

DECLARE @IDs TABLE(ID INT);



- - 对INSERT语句进行微小更改;添加一个OUTPUT子句:

INSERT dbo.foo(name)

OUTPUT inserted.ID INTO @IDs(ID)

SELECT N'Fred '

UNION ALL

SELECT N'Bob';



来自@IDs的SELECT ID;



http ://stackoverflow.com/questions/9477502/get-the-last-inserted-row-id-with-sql-statement [ ^ ]
DECLARE @IDs TABLE(ID INT);

-- minor change to INSERT statement; add an OUTPUT clause:
INSERT dbo.foo(name)
OUTPUT inserted.ID INTO @IDs(ID)
SELECT N'Fred'
UNION ALL
SELECT N'Bob';

SELECT ID FROM @IDs;

http://stackoverflow.com/questions/9477502/get-the-last-inserted-row-id-with-sql-statement[^]


1。使用上面的代码创建存储过程

2.调用此存储过程 http: //msdn.microsoft.com/en-us/library/vstudio/37hwc7kt.aspx [ ^ ]

3. asp.net页面中的inser值http://stackoverflow.com/questions/370201/why-will-expressions- as-property-values-on-a-server-controls-lead-to-a-co [ ^ ]
1. create stored procedure with code above
2. invoke this store procedre http://msdn.microsoft.com/en-us/library/vstudio/37hwc7kt.aspx[^]
3. inser value in asp.net page http://stackoverflow.com/questions/370201/why-will-expressions-as-property-values-on-a-server-controls-lead-to-a-co[^]


这篇关于如何在插入时间过程中获取任何表的Id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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