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

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

问题描述

我想通过我的传统的ASP一些参数SQL存储过程。我已经看到了就这个问题和不知道的几个职位我在做什么错了,因为我似乎没有看到我的差异。

 设置康恩=的CreateObject(ADODB.Connection)
conn.open(DSN = SERVER; UID =用户名; PWD = PWD;数据库= MyDatabase的) 设置CMD =的Server.CreateObject(ADODB.Command)
 设置cmd.ActiveConnection =康恩
 cmd.CommandType = adCmdStoredProc
 cmd.CommandText = MY_PROC
 cmd.Parameters.Refresh
 cmd.Parameters(1)=MyParam集RS = cmd.execute

我得到的错误


参数的错误类型,超出可接受的范围,或有冲突
彼此。

就行了 cmd.CommandType = adCmdStoredProc 。我也试着做它与同样的错误如下方式

 设置康恩=的CreateObject(ADODB.Connection)
conn.open(DSN = SERVER; UID =用户名; PWD = PWD;数据库= MyDatabase的) 设置CMD =的Server.CreateObject(ADODB.Command)
 设置cmd.ActiveConnection =康恩
 cmd.CommandType = adCmdStoredProc
 cmd.CommandText = MY_PROC
 cmd.Parameters.Refresh
 cmd.Parameters.Append cmd.CreateParameter(@ MyParam,adVarWChar,adParamInput,50,测试)集RS = cmd.execute


解决方案

您通过使用ADO 后期绑定,这意味着常量如 adCmdStoredProc adParamInput 等都是未知到code(所以他们总是0)。

您可以找一找,并确定你需要为一个常数在code中的那些(或直接使用数字,但如果你下再以后编辑$ C $,这不是很好读)。

还是先看看这里在MSDN上 - 你可能会发现,在结果定义所有常量的文件
C:\\ Program Files文件\\ Common Files文件\\系统\\ ADO \\ adovbc.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 Files\Common Files\System\ado\adovbc.inc.

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

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