感谢所有建议SELECT SCOPE_IDENTITY()的人。我能够创建一个存储过程:
USE [dbname]GO SET ANSI_NULLS onGOSET QUOTED_IDENTIFIER onGOCREATE PROCEDURE [dbo].[spInsert]( @Nn varchar(30))ASBEGIN TRANSACTION InsertRecord INSERT INTO A (Nn) VALUES (@Nn) SELECT NewID = SCOPE_IDENTITY() -- returns the new record ID of this transaction COMMIT TRANSACTION InsertRecord
并使用VB调用存储过程:
Dim strNn '<- var to be passed'Set cn = Server.CreateObject("ADODB.Connection") connectString = "DSN" cn.Open connectString, "user", "PW0rd" Set rs = Server.CreateObject("ADODB.Recordset") set rs = cn.Execute("EXEC [dbname].[dbo].[A] @Nn=" & strNn)'return the value'resultID = rs(0)
现在,只要我引用新创建的ID,就可以使用resultID。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)