在 VBScript 中使用输出参数调用 SQL 存储过程 [英] Calling SQL Stored Procedure with Output Parameter in VBScript
问题描述
我编写了一个 VBScript 函数来调用存储过程.过去,我编写了许多使用输入参数调用存储过程的函数,但在这种情况下,我需要使用输出参数.
在另一个应用程序中,我使用实体框架调用完全相同的存储过程,因此存储过程很好.
这是我的代码:
<块引用>函数 checkAccess(userid,link)isAllowed = 假设置 cmd = Server.CreateObject("ADODB.Command")cmd.CommandText = "Check_Permission"cmd.ActiveConnection = 连接cmd.NamedParameters = truecmd.CommandType = adCmdStoredProccmd.Parameters.Append(cmd.CreateParameter("@Login", adVarChar, adParamInput, 50, userId))cmd.Parameters.Append(cmd.CreateParameter("@LinkId", adInteger, adParamInput, 50, 链接))cmd.Parameters.Append(cmd.CreateParameter("@IsAllowed", adBoolean, adParamOutput, 10, isAllowed))checkAccess = isAllowed结束功能
此函数始终返回 false.如何让它发挥作用?
你应该返回你的输出参数的值:
checkAccess = cmd.Parameters("@IsAllowed").Value
此外,ADO 中的输出参数不需要初始值,adBoolean 参数不需要大小,因此您可以将最后一个参数更改为:
cmd.Parameters.Append(cmd.CreateParameter("@IsAllowed", adBoolean, adParamOutput))
你也可以去掉你的 isAllowed 变量,因为它不再需要了.
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?
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.
这篇关于在 VBScript 中使用输出参数调用 SQL 存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!