经典ASP - ADO执行存储过程传入​​参数

时间:2014-02-04 19:31:10

标签: stored-procedures asp-classic ado

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

我的sproc params是这样的:

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

然后我试着这样做:

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'
  参数类型错误,超出可接受的范围,或彼此冲突。

我已经尝试过Command的东西而且我得到了“精确”错误 我“有”使用命令对象吗?

e.g。

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")

1 个答案:

答案 0 :(得分:13)

以下是如何操作,您不需要创建记录集对象,因为它是更新存储过程:

'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