Classic ASP - ADO execute Stored Procedure passing in parameters

霸气de小男生 提交于 2020-01-10 09:02:52

问题


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

(I don't need a Recordset, i'm just trying to get it to send in data)

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?

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:


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


来源:https://stackoverflow.com/questions/21561657/classic-asp-ado-execute-stored-procedure-passing-in-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!