简体   繁体   English

在VBScript中调用Output参数的SQL存储过程

[英]Calling SQL Stored Procedure with Output Parameter in VBScript

I've written a VBScript function to call a stored procedure.我写了一个 VBScript function 来调用存储过程。 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.过去,我编写了很多调用带输入参数的存储过程的函数,但在本例中,我需要使用 Output 参数。

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.这个 function 总是返回 false。 How do I make it work?我如何让它发挥作用?

You should return the value of your output parameter:您应该返回 output 参数的值:

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:此外,ADO 中的 output 参数不需要初始值,adBoolean 参数不需要大小,因此您可以将最后一个参数更改为:

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

You could also get rid of your isAllowed variable since it is no longer necessary.您也可以删除 isAllowed 变量,因为它不再是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用SQL Server的输出参数调用Oracle存储过程 - Calling Oracle stored procedure with output parameter from SQL Server 调用使用来自Microsoft SQL Server的输出参数的Oracle存储过程 - Calling an Oracle stored procedure that uses an output parameter from Microsoft SQL Server 从VB.NET应用程序调用SQL Server存储过程。 输出参数恢复为空白 - Calling SQL Server stored procedure from VB.NET application. Output parameter is coming back blank 从存储过程中获取 Output 参数而不调用 execute() - Get Output parameter from stored procedure without calling execute() 调用存储过程时动态调用T-SQL - T-SQL cast parameter on the fly when calling a stored procedure 使用表形式的参数调用存储过程 - Calling a stored procedure with a parameter that is a table 在sql存储过程中将输出参数设置为count()的值 - Setting an output parameter to the value of count() in sql stored procedure 分页脚本中的存储过程和输出参数(SQL Server 2008) - Stored Procedure and output parameter from paging script (SQL Server 2008) Sybase-存储过程-将SQL查询的结果存储到OUTPUT参数中 - Sybase - Stored procedure - Store results of a SQL query into an OUTPUT parameter 使用输出参数在ASP.NET中调用SQL存储过程 - Call a SQL stored procedure in ASP.NET with an output parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM