使用 ASP 将参数传递给存储过程 [英] Passing Parameters to a Stored Procedure using ASP

查看:40
本文介绍了使用 ASP 将参数传递给存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些参数传递给我的经典 ASP 中的 SQL 存储过程.我已经看过几篇关于此的帖子,但不确定我做错了什么,因为我似乎没有看到我的差异.

set conn = CreateObject("ADODB.Connection")conn.open ("DSN=SERVER;UID=username;PWD=pwd;Database=MyDatabase")设置 cmd = Server.CreateObject("ADODB.Command")设置 cmd.ActiveConnection = conncmd.CommandType = adCmdStoredProccmd.CommandText = my_proccmd.Parameters.Refreshcmd.Parameters(1) = "MyParam"设置 rs = cmd.execute

我收到错误

<前>参数类型错误、超出可接受范围或发生冲突与彼此.

cmd.CommandType = adCmdStoredProc 行上.我也尝试以相同的错误按以下方式进行

set conn = CreateObject("ADODB.Connection")conn.open ("DSN=SERVER;UID=username;PWD=pwd;Database=MyDatabase")设置 cmd = Server.CreateObject("ADODB.Command")设置 cmd.ActiveConnection = conncmd.CommandType = adCmdStoredProccmd.CommandText = my_proccmd.Parameters.Refreshcmd.Parameters.Append cmd.CreateParameter("@MyParam, adVarWChar, adParamInput, 50, "test")设置 rs = cmd.execute

解决方案

你通过 late binding 使用 ADO,这意味着像 adCmdStoredProcadParamInput 这样的常量 等对您的代码是未知的(因此它们始终为 0).

您可以查找它们并将所需的定义为代码中的常量(或直接使用数字,但如果稍后再次编辑代码,则可读性不佳).

或者看看在 msdn 上 - 您可能会在
找到定义所有常量的文件c:Program FilesCommon FilesSystemadoadovbc.inc.

I'm trying to pass some parameters to a SQL stored procedure in my classic ASP. I've seen several posts on this and not sure what I'm doing wrong as I don't seem to see my discrepancy.

set conn = CreateObject("ADODB.Connection") 
conn.open ("DSN=SERVER;UID=username;PWD=pwd;Database=MyDatabase")

 set cmd = Server.CreateObject("ADODB.Command")
 set cmd.ActiveConnection = conn
 cmd.CommandType = adCmdStoredProc
 cmd.CommandText = my_proc
 cmd.Parameters.Refresh
 cmd.Parameters(1) = "MyParam"

set rs = cmd.execute

I'm getting the error

Arguments are of the wrong type, are out of acceptable range, or are in conflict 
with one another.

on the line cmd.CommandType = adCmdStoredProc. I also tried to do it the following way with the same error

set conn = CreateObject("ADODB.Connection") 
conn.open ("DSN=SERVER;UID=username;PWD=pwd;Database=MyDatabase")

 set cmd = Server.CreateObject("ADODB.Command")
 set cmd.ActiveConnection = conn
 cmd.CommandType = adCmdStoredProc
 cmd.CommandText = my_proc
 cmd.Parameters.Refresh
 cmd.Parameters.Append cmd.CreateParameter("@MyParam, adVarWChar, adParamInput, 50, "test")

set rs = cmd.execute

解决方案

You use ADO through late binding, which means that the constants like adCmdStoredProc, adParamInput etc. are unknown to your code (so they are always 0).

You can either look them up and define the ones you need as a constant in your code (or use the numbers directly, but that's not well readable if you edit the code again later).

Or take a look here on msdn - you may find a file that defines all the constants at
c:Program FilesCommon FilesSystemadoadovbc.inc.

这篇关于使用 ASP 将参数传递给存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆