Calling SQL Stored Procedure with Output Parameter in VBScript

萝らか妹 提交于 2019-12-04 01:09:37

问题


I've written a VBScript function to call a stored procedure. In the past, I've written a number of functions calling stored procedures with input parameters, but in this instance, I need to work with an Output parameter.

In another application, I call the exact same stored procedure using the Entity Framework, so the stored procedure is fine.

Here's my code:

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

This function always returns false. How do I make it work?


回答1:


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.



来源:https://stackoverflow.com/questions/10017872/calling-sql-stored-procedure-with-output-parameter-in-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!