经典 ASP - ADO 执行传入参数的存储过程 [英] Classic ASP - ADO execute Stored Procedure passing in parameters

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

问题描述

我需要使用 Classic ASP 将参数传递到存储过程.我确实看到有些人使用 Command 对象而其他人不使用它.

I am needing to pass parameters into a stored procedure with Classic ASP. I do see some people using the Command object and others NOT using it.

我的存储过程参数是这样的:

My sproc params are like this:

@RECORD_NUMBER decimal(18,0),
@ErrorType nvarchar(100),
@INSURANCE_CODE smallint,
@CompanyId int,
@INS_ID_NUM nchar(22)   

然后我正在尝试这样做:

Then I'm trying to do this:

Dim conn, rsSet,rsString, cmd

Dim RN,ET,IC,CI,IIN
RN = Request.Form("Record_Number")
ET = Request.Form("ErrorType")
IC = Request.Form("INSURANCE_CODE")
CI = Request.Form("CompanyID")
IIN = Request.Form("INS_ID_NUM")

set conn = server.CreateObject("adodb.connection")
set rsSet = Server.CreateObject ("ADODB.Recordset")


conn.Open Application("conMestamed_Utilities_ConnectionString")
rs_string = "apUpdateBill " & RN &",'" &  ET & "'," & IC & "," & CI & ",'" & IIN & "'"
rsSet.Open rsString, conn, adOpenForwardOnly,, adCmdText

(我不需要 Recordset,我只是想让它发送数据)

错误:
ADODB.Recordset 错误800a0bb9"
参数类型错误、超出可接受范围或相互冲突.

Error:
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

我已经尝试过命令的东西,但我得到了精确"错误我必须"使用命令对象吗?

I have tried Command stuff and I get "precision" errors Do I "have" to use command object?

例如

Set cmd = Server.CreateObject("ADODB.Command")
'Set cmd.ActiveConnection = conn
'cmd.CommandText = "apUpdateBill"
'cmd.CommandType = adCmdStoredProc
'Cmd.Parameters.append Cmd.createParameter("@Record_Number", adDecimal, adParamInput, 18)
'Cmd.Parameters("@Record_Number").Precision = 0
'Cmd.Parameters("@Record_Number").value = Request.Form("Record_Number")

推荐答案

你会这样做,你不需要创建记录集对象,因为它是一个更新存储过程:

Here is how you would do it, you won't need to create a recordset object since it is an update stored procedure:

'Set the connection
'...............

'Set the command
DIM cmd
SET cmd = Server.CreateObject("ADODB.Command")
SET cmd.ActiveConnection = Conn


'Prepare the stored procedure
cmd.CommandText = "apUpdateBill"
cmd.CommandType = 4  'adCmdStoredProc

cmd.Parameters("@RECORD_NUMBER") = Request.Form("Record_Number") 
cmd.Parameters("@ErrorType") = Request.Form("ErrorType") 
cmd.Parameters("@INSURANCE_CODE") = Request.Form("INSURANCE_CODE")
cmd.Parameters("@CompanyId") = Request.Form("CompanyID") 
cmd.Parameters("@INS_ID_NUM") = Request.Form("INS_ID_NUM")

'Execute the stored procedure
'This returns recordset but you dont need it
cmd.Execute

Conn.Close
SET Conn = Nothing

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

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