7

我编写了一个 VBScript 函数来调用存储过程。过去,我编写了许多使用输入参数调用存储过程的函数,但在这种情况下,我需要使用输出参数。

在另一个应用程序中,我使用实体框架调用完全相同的存储过程,因此存储过程很好。

这是我的代码:

Function checkAccess(userid,link)
    isAllowed = false

    set cmd = Server.CreateObject("ADODB.Command")
    cmd.CommandText = "Check_Permission"
    cmd.ActiveConnection = Conn
    cmd.NamedParameters = true
    cmd.CommandType = adCmdStoredProc
    cmd.Parameters.Append(cmd.CreateParameter("@Login", adVarChar, adParamInput, 50, userId))
    cmd.Parameters.Append(cmd.CreateParameter("@LinkId", adInteger, adParamInput, 50, link))    
    cmd.Parameters.Append(cmd.CreateParameter("@IsAllowed", adBoolean, adParamOutput, 10, isAllowed))

    checkAccess = isAllowed
End Function

此函数始终返回 false。我如何使它工作?

4

1 回答 1

15

You should return the value of your output parameter:

checkAccess = cmd.Parameters("@IsAllowed").Value

Also, output parameters in ADO don't require an initial value and adBoolean parameters don't require a size, so you could change your the last paramter to:

cmd.Parameters.Append(cmd.CreateParameter("@IsAllowed", adBoolean, adParamOutput))

You could also get rid of your isAllowed variable since it is no longer necessary.

于 2012-04-04T19:26:40.050 回答