This is an extension to: Returning SCOPE_IDENTITY() using Adodb.Command
Trying to get SCOPE_IDENTITY() using ADO.Command from a SP but get an error when I run the Ado.Command.. Here is the code example:
The Stored Procedure:
CREATE PROCEDURE TESTSP
@LASTID int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO TABLE1 (VAL1,VAL2) VALUES (VAL1,VAL2)
SET @LASTID = SCOPE_IDENTITY()
The ADO Request:
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
This is causing the error: LastIDParameter = SQLCOMM.CreatePar开发者_StackOverflow社区ameter("@LastID",3,2)
Your line:
SQLCOMM.CommandType = 1
should be instead:
SQLCOMM.CommandType = CommandType.StoredProcedure
精彩评论