这是对以下内容的扩展: Returning SCOPE_IDENTITY() using Adodb.Command
尝试从SP使用ADO.Command获取SCOPE_IDENTITY(),但在运行Ado.Command时出错。以下是代码示例:
存储过程:
CREATE PROCEDURE TESTSP
@LASTID int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO TABLE1 (VAL1,VAL2) VALUES (VAL1,VAL2)
SET @LASTID = SCOPE_IDENTITY()
ADO请求:
set SQLCOMM = Server.CreateObject("ADODB.Command")
SQLCOMM.ActiveConnection = CONNSTRING
SQLCOMM.CommandText = TESTSP
SQLCOMM.CommandType = 1
SQLCOMM.CommandTimeout = 0
SQLCOMM.Prepared = true
LastIDParameter = SQLCOMM.CreateParameter("@LastID",3,2)
SQLCOMM.Parameters.Add(LastIDParameter)
SQLCOMM.Execute()
INSERT_RETURNS_SCOPEID=LastIDParameter.Value
set SQLCOMM=Nothing
这导致错误:LastIDParameter = SQLCOMM.CreateParameter("@LastID",3,2)
答案 0 :(得分:1)
你的专栏:
SQLCOMM.CommandType = 1
应该是:
SQLCOMM.CommandType = CommandType.StoredProcedure