简体   繁体   中英

ADO Parameter Error in VBScript

I have tried many, many things, but keep getting error 3001 (Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another) when trying to add parameters to a command object.

Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = con
cmd.CommandText = "ProcName"                
cmd.CommandType = 4 'adCmdStoredProc

MsgBox("0")
'cmd.Parameters.Append(cmd.CreateParameter("@InvoiceNumber", adVarChar, adParamInput, 100, sInvoice))
Set pInvoiceNumber = cmd.CreateParameter("@InvoiceNumber", adVarChar, adParamInput, 100, sInvoice)
cmd.Parameters.Append(pInvoiceNumber)

The connection object is valid and open at the time that this code runs. The @InvoiceNumber parameter of the stored procedure is a varchar(100). What am I missing here?

I'm not able to replicate the issue, but I'm working in Classic ASP. I found this post which sounds like it may be relevant though.

VBA: Run-time error 3001 Arguments Are Of The Wrong Type... when setting ADODB.Command object members

It seems the adVarChar and adParamInput constants may be the problem due to late binding. The resolution was to add the constants to the Sub header.

If that's not feasible, try using Oracle Certified Professional's suggestion of Refresh

Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = con
cmd.CommandText = "ProcName"                
cmd.CommandType = 4 'adCmdStoredProc
cmd.Parameters.Refresh
cmd.Parameters(0).Value  = sInvoice

我在asp.page顶部使用包含库ADOLib.inc解决了该问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM