0

我正在将一些代码从构造字符串转换为参数化查询,遇到命令对象问题。

if (session("pafWebService") = true) then

Dim adoCMD 
Dim adoRS 
Dim strSQL 
Dim lRecordsAffected 

strSQL =  "insert into job values  (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,)" 

Set adoCMD = Server.CreateObject("ADODB.Command")
With adoCMD
.ActiveConnection = conn
.CommandText = strSQL
.CommandType = adCmdText
.parameters.Append .CreateParameter("account", adVarChar, adParamInput, 16 , cCustcode)
.parameters.Append .CreateParameter("reference", adVarChar, adParamInput, 40 , cReference)
.parameters.Append .CreateParameter("priority", adVarChar, adParamInput, 3 , cPriority)
.parameters.Append .CreateParameter("colldate", adVarChar, adParamInput, 8 , cCollDate)
.parameters.Append .CreateParameter("deldate", adVarChar, adParamInput, 8 , cDelDate)
.parameters.Append .CreateParameter("onby", adInterger, adParamInput, 4 , nOnby)
.parameters.Append .CreateParameter("timestart", adVarChar, adParamInput, 4 , cTimestart)
.parameters.Append .CreateParameter("timeend", adVarChar, adParamInput, 4 , cTimeend)
.parameters.Append .CreateParameter("delname", adVarChar, adParamInput, 40 , cDelname)
.parameters.Append .CreateParameter("deladd1", adVarChar, adParamInput, 40 , cAdd1)
.parameters.Append .CreateParameter("deladd2", adVarChar, adParamInput, 40 , cAdd2)
.parameters.Append .CreateParameter("deladd3", adVarChar, adParamInput, 40 , cAdd3)
.parameters.Append .CreateParameter("deltown", adVarChar, adParamInput, 40 , cAdd4)
.parameters.Append .CreateParameter("delcounty", adVarChar, adParamInput, 40 , cAdd5)
.parameters.Append .CreateParameter("delpostcode", adVarChar, adParamInput, 10 , cPostcode)
.parameters.Append .CreateParameter("goods", adVarChar, adParamInput, 40 , cGoods)
.parameters.Append .CreateParameter("wgt", adInteger, adParamInput, 4 , nWgt)
.parameters.Append .CreateParameter("qty", adInteger, adParamInput, 4 , nQty)
.parameters.Append .CreateParameter("plt", adInteger, adParamInput, 4 , nPlt)
.parameters.Append .CreateParameter("vol", adInteger, adParamInput, 4 , nVol)
.parameters.Append .CreateParameter("haz", adInteger, adParamInput, 4 , nHaz)
.parameters.Append .CreateParameter("adr", adVarChar, adParamInput, 10 , cadr)
.parameters.Append .CreateParameter("adrpack", adVarchar, adParamInput, 10 , cAdrpack)
.parameters.Append .CreateParameter("taillift", adInteger, adParamInput, 4 , nTl)
.parameters.Append .CreateParameter("rigid", adInteger, adParamInput, 4 , nRi)
.parameters.Append .CreateParameter("ringforbook", adInteger, adParamInput, 4 , nBook)
.parameters.Append .CreateParameter("notes", adVarChar, adParamInput, 250 , cNotes)
.parameters.Append .CreateParameter("phoneno", adVarChar, adParamInput, 30 , cPhoneNo)
.parameters.Append .CreateParameter("userid", adInteger, adParamInput, 4 , session("userid"))
.parameters.Append .CreateParameter("confirmed", adInteger, adParamInput, 4 ,0)
.parameters.Append .CreateParameter("processed", adInteger, adParamInput, 4 ,0)
.parameters.Append .CreateParameter("adrname", adVarchar, adParamInput, 30 ,cAdrname)
.parameters.Append .CreateParameter("adrchem", adVarchar, adParamInput, 10 ,cAdrchem)
.parameters.Append .CreateParameter("timestartc", adVarchar, adParamInput, 4 ,ctimestartcol)
.parameters.Append .CreateParameter("timeendc", adVarchar, adParamInput, 4 ,ctimeendcol)
.parameters.Append .CreateParameter("confno", adInteger, adParamInput, 4 ,0)
.parameters.Append .CreateParameter("jobno", adInteger, adParamInput, 4 ,0)
.parameters.Append .CreateParameter("fplt", adInteger, adParamInput, 4 , nfPlt)
.parameters.Append .CreateParameter("hplt", adInteger, adParamInput, 4 , nhPlt)
.parameters.Append .CreateParameter("qplt", adInteger, adParamInput, 4 , nqPlt)
.parameters.Append .CreateParameter("coll1", adVarChar, adParamInput, 30 ,cColl1)
.parameters.Append .CreateParameter("coll2", adVarChar, adParamInput, 30 ,cColl2)
.parameters.Append .CreateParameter("coll3", adVarChar, adParamInput, 30 ,cColl3)
.parameters.Append .CreateParameter("coll4", adVarChar, adParamInput, 30 ,cColl4)
.parameters.Append .CreateParameter("coll5", adVarChar, adParamInput, 30 ,cColl5)
.parameters.Append .CreateParameter("collp", adVarChar, adParamInput, 30 ,cCollp)
.parameters.Append .CreateParameter("colname", adVarChar, adParamInput, 30 ,cColname)
.parameters.Append .CreateParameter("printed", adBoolean, adParamInput, 1 ,false)
.parameters.Append .CreateParameter("cheps", adInteger, adParamInput, 4 ,nCheps)
.parameters.Append .CreateParameter("countryd", adVarChar, adParamInput, 30 ,ccountryd)
.parameters.Append .CreateParameter("countryc", adVarChar, adParamInput, 30 ,ccountryc)
.parameters.Append .CreateParameter("uniqueid", adVarChar, adParamInput, 30 ,cUniqueId)
.parameters.Append .CreateParameter("co2", adInteger, adParamInput, 10 , request.form("cC02"))
.parameters.Append .CreateParameter("carbon", adInteger, adParamInput, 10 , request.form("cCarbon"))
.parameters.Append .CreateParameter("am", adInteger, adParamInput, 4 ,nAM)
.parameters.Append .CreateParameter("pm", adInteger, adParamInput, 4 ,nPM)
.parameters.Append .CreateParameter("instructs", adVarChar, adParamInput, 50 ,cSpecialInstruct)
.parameters.Append .CreateParameter("quote", adVarChar, adParamInput, 59 , trim(cQuoteId))
.parameters.Append .CreateParameter("validdel", adBoolean, adParamInput, 1 , lValidDel)
.parameters.Append .CreateParameter("validcol", adBoolean, adParamInput, 1 , lValidcol)
Set adoRS = .Execute(lRecordsAffected)

  end with  

错误信息:ADODB.Command 错误 '800a0bb9'

参数类型错误、超出可接受范围或相互冲突。(指向 .CommandType = adCmdText 行)任何帮助表示赞赏

4

1 回答 1

0

this occurs when an value is empty (vbscript datatype)-

you have to make sure that e.g. an integer value is definitly NULL and not empty... (or 0,1,2...)

you could write a function to "parse" vbscript values to their correct datatype like so:

function parse(value, alternative)
    dim val
    val = trim(value & "")
    parse = alternative
    if val = "" then exit function
    on error resume next
    select case varType(parse)
        case 2, 3 'integer, long
            parse = cLng(val)
        case 4, 5 'single, double
            parse = cdbl(val)
        case 6  'currency
            parse = ccur(val)
        case 7 'date
            parse = cDate(val)
        case 11 'bool
            parse = cBool(val)
        case 8 'string
            parse = value & ""
        case else
            on error goto 0
            err.raise 1024, "parse(value, alternative)", "Type is not supported. val:" & value & " alt:" & alternative)
    end select
    on error goto 0
end function

' call of parse function:
cCustcode = parse(cCustcode, "")
'or for an integer:
nWgt = parse(nWgt, 0)
于 2013-01-09T14:29:30.300 回答