Access ADODB - 过程或函数指定的参数太多
Access ADODB - Procedure or function has too many arguments specified
我最近开始使用 ADODB 来执行存储过程,但 运行 遇到了一些麻烦。每当我尝试 运行 这个特定的存储过程时,它都会给我错误: Run-time error '-2147217900 (80040e14)': [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function CheckTeamMember has too many arguments specified.
但是,当我仔细检查 vba 中的调用和 sql 服务器中的 SP 时他们都有相同数量的参数,3.
这是SP:
CREATE PROC [dbo].[CheckTeamMember] (
@projectID VARCHAR(45),
@empID INT,
@exists BIT OUTPUT
)
AS
DECLARE @trueFalse BIT;
SET @trueFalse = 0
IF EXISTS (SELECT TOP 1 projectteammember_id FROM ci_projectteammember
INNER JOIN ci_projectteam ON ci_projectteammember.projectteammember_team = ci_projectteam.projectteam_id
WHERE ci_projectteam.projectteam_project = @projectID AND projectteammember_member = @empID)
BEGIN
SET @trueFalse = 1
END
ELSE
BEGIN
SET @trueFalse = 0
END
SELECT @exists = @trueFalse
这是 vba 中的代码(这是一个 class 模块。我在 运行 实际查询函数之前 运行 init() :
Option Compare Database
Option Explicit
Private conDB As adodb.Connection
Private cmdCheckTeamMember As adodb.Command
Public Sub init(con As String)
Set conDB = New adodb.Connection
conDB.ConnectionString = con
conDB.Open
Set cmdCheckTeamMember = New adodb.Command
With cmdCheckTeamMember
.ActiveConnection = conDB
.CommandType = adCmdStoredProc
.CommandText = "CheckTeamMember"
.Prepared = True
End With
End Sub
Public Function checkTeamMember(projectID As String, empID As Integer) As Boolean
Dim exists As Boolean
With cmdCheckTeamMember
.Parameters.Append .CreateParameter("@projectID", adVarChar, adParamInput, 45, projectID)
.Parameters.Append .CreateParameter("@empID", adInteger, adParamInput, , empID)
.Parameters.Append .CreateParameter("@exists", adBoolean, adParamInputOutput, , exists)
.Execute
End With
checkTeamMember = exists
End Function
如果你想re-use一个命令,你只需要添加一次参数。所以添加Init
中的参数,只访问ckdCheckTeammember
中的参数。类似于:
Public Function checkTeamMember(projectID As String, empID As Integer) As Boolean
Dim exists As Boolean
With cmdCheckTeamMember
.Parameters("@projectID").value = projectID
.Parameters("@empID").value = empID
.Execute
exists = .Parameters("@exists").value
End With
checkTeamMember = exists
End Function
我最近开始使用 ADODB 来执行存储过程,但 运行 遇到了一些麻烦。每当我尝试 运行 这个特定的存储过程时,它都会给我错误: Run-time error '-2147217900 (80040e14)': [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function CheckTeamMember has too many arguments specified.
但是,当我仔细检查 vba 中的调用和 sql 服务器中的 SP 时他们都有相同数量的参数,3.
这是SP:
CREATE PROC [dbo].[CheckTeamMember] (
@projectID VARCHAR(45),
@empID INT,
@exists BIT OUTPUT
)
AS
DECLARE @trueFalse BIT;
SET @trueFalse = 0
IF EXISTS (SELECT TOP 1 projectteammember_id FROM ci_projectteammember
INNER JOIN ci_projectteam ON ci_projectteammember.projectteammember_team = ci_projectteam.projectteam_id
WHERE ci_projectteam.projectteam_project = @projectID AND projectteammember_member = @empID)
BEGIN
SET @trueFalse = 1
END
ELSE
BEGIN
SET @trueFalse = 0
END
SELECT @exists = @trueFalse
这是 vba 中的代码(这是一个 class 模块。我在 运行 实际查询函数之前 运行 init() :
Option Compare Database
Option Explicit
Private conDB As adodb.Connection
Private cmdCheckTeamMember As adodb.Command
Public Sub init(con As String)
Set conDB = New adodb.Connection
conDB.ConnectionString = con
conDB.Open
Set cmdCheckTeamMember = New adodb.Command
With cmdCheckTeamMember
.ActiveConnection = conDB
.CommandType = adCmdStoredProc
.CommandText = "CheckTeamMember"
.Prepared = True
End With
End Sub
Public Function checkTeamMember(projectID As String, empID As Integer) As Boolean
Dim exists As Boolean
With cmdCheckTeamMember
.Parameters.Append .CreateParameter("@projectID", adVarChar, adParamInput, 45, projectID)
.Parameters.Append .CreateParameter("@empID", adInteger, adParamInput, , empID)
.Parameters.Append .CreateParameter("@exists", adBoolean, adParamInputOutput, , exists)
.Execute
End With
checkTeamMember = exists
End Function
如果你想re-use一个命令,你只需要添加一次参数。所以添加Init
中的参数,只访问ckdCheckTeammember
中的参数。类似于:
Public Function checkTeamMember(projectID As String, empID As Integer) As Boolean
Dim exists As Boolean
With cmdCheckTeamMember
.Parameters("@projectID").value = projectID
.Parameters("@empID").value = empID
.Execute
exists = .Parameters("@exists").value
End With
checkTeamMember = exists
End Function