2013-10-17 68 views
0

vbscript的新手位,不是特別喜歡它,但我的客戶端使用它,所以我不能做太多的事情!我無法使用參數化查詢將數據添加到數據庫中!請救我傢伙!ADO中的參數化查詢 - 將數據添加到數據庫中

到目前爲止,現有的代碼是

function ecaddupdateDEV (thistable, idvar, vararray) 

for each varname in vararray 
    valstring = valstring & ", session(""" & varname & """)" 
     thesefields = thesefields & ", " & varname 
    next 
    thesefields = idvar & thesefields 
    valstring = " array(" & ecremovel(valstring, 2) & ")" 
    vals = eval(valstring) 

set temprs = Server.CreateObject("ADODB.RecordSet") 

    if session(idvar) = 0 then 
    'response.Write("chid is 0 add new record") 
    ' ADD THIS REC 
    temprs.open thistable, db,1,3,2 
    temprs.AddNew vararray, vals 
    ecaddupdateDEV = temprs(idvar) 
    temprs.close 

    set temprs = ecquery("select " & idvar & " from " & thistable & " order by " & idvar & " desc ") 
    ecaddupdateDEV = temprs(idvar) 
    else 
    ' UPDATE THIS REC 
    selectclause = "select " & thesefields & " from " & thistable & " where " & idvar & " = " & session(idvar) 
    temprs.open selectclause, db ,1,3 
    temprs.update vararray, vals 
    ecaddupdateDEV = temprs(idvar) 
    temprs.close 
    end if 
    set temprs = nothing 
end function 

的temprs可變我要讓參數爲安全起見,顯然哈哈!我只是不知道該怎麼做!我讀過的東西我只是感到困惑,請幫助!提前謝謝了!

回答

0

而不是一個記錄集,使用命令。下面是這個例子,它可以讓你繼續下去,但是你可能需要調整它,因爲根據經驗,命名參數並不真正起作用,所以你可以按照它們在SQL語句中出現的順序來賦值。

How To Call a Parameterized Query to an Access Database with ADO

+0

感謝您的鏈接,我一定會申請這個,看看我去!再次感謝你!! –