我正在将一些代码从构造字符串转换为参数化查询,遇到命令对象问题。
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) 任何帮助表示赞赏
答案 0 :(得分:0)
当值为空(vbscript数据类型) -
时会发生这种情况你必须确保例如一个整数值肯定是NULL而不是空...(或0,1,2 ...)
您可以编写一个函数来将vbscript值“解析”为正确的数据类型,如下所示:
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)