错误'800a01b6':对象不支持此属性或方法:Object.Parameters.Add'

时间:2021-09-22 21:32:37

This is an extension to: Returning SCOPE_IDENTITY() using Adodb.Command

这是对以下内容的扩展:使用Adodb.Command返回SCOPE_IDENTITY()

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:

尝试从SP使用ADO.Command获取SCOPE_IDENTITY()但在运行Ado.Command时出错。以下是代码示例:

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:

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

This is causing the error: LastIDParameter = SQLCOMM.CreateParameter("@LastID",3,2)

这导致错误:LastIDParameter = SQLCOMM.CreateParameter(“@ LastID”,3,2)

1 个解决方案

#1


1  

Your line:

你的路线:

SQLCOMM.CommandType = 1

should be instead:

应该是:

SQLCOMM.CommandType = CommandType.StoredProcedure

#1


1  

Your line:

你的路线:

SQLCOMM.CommandType = 1

should be instead:

应该是:

SQLCOMM.CommandType = CommandType.StoredProcedure