2012-05-21 26 views
1

結果不允許操作我有這樣的代碼:經典ASP MySQL的INSERT得到當對象被關閉

Set oConnection = Server.CreateObject("ADODB.Connection") 
Set oRecordset = Server.CreateObject("ADODB.Recordset") 

oConnection.Open "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;UID=xxxx;PWD=xxxx;DATABASE=xxxx; OPTION=3;" 
    Sqltemp = "INSERT INTO rsvptable (fname, lname, fbid, rsvp, streetaddress, city, state, zip, streetaddress2, cellphone, acode) " & _ 
       "VALUES ('" & firstName & "', '" & lastName & "', " & fb & ", 0, '" & address1 & "', '" & city & "', '" & strState & "', " & zip & ", '" & address2 & "', " & cell & ", " & returnedNums & ")" 

set newAdd = oConnection.execute(Sqltemp) 

if newAdd.EOF then 
    response.write "end" 
else 
    response.write "not end" 
end if 

它不斷告訴我這一點:

ADODB.Recordset錯誤「800a0e78」

當對象關閉時不允許操作。

/add.asp,線136

線136是這樣的:

if newAdd.EOF then 

什麼,我會在這裏可以俯瞰?

UPDATE

發現我的答案在這裏! :O)

How to tell if a db update was successful?

+0

+1 - 總是很高興看到人們爲自己的問題尋找解決方案 - 並且儘可能使用Command對象 - 如此讚揚 – HeavenCore

回答

1

兩件事情:

  1. 定義oRecordset的記錄,但後來使用&檢查EOF上newAdd
  2. 你爲什麼試圖填充自刀片查詢recordet?
+0

我期待得到1或0,如果它插入或不.. – StealthRT

+0

'oConnection.execute(Sqltemp,rowsMo​​dified)'或類似的東西。我不擅長VB。然後檢查'rowsMo​​dified',如果插入成功則它必須是1。如果失敗則爲0(在這種情況下,實際上你會得到一個錯誤)。 – AlexanderMP

+0

它現在說**調用Sub oConnection.execute時不能使用圓括號(Sqltemp,intAffectedRows)** – StealthRT

1

http://www.w3schools.com/ado/met_conn_execute.asp

的結果被存儲在一個新的記錄對象,如果它是一個 行返回的查詢。如果 不是行返回查詢,則將返回一個關閉的Recordset對象。

INSERT不是行返回的查詢,因此它返回一個關閉的記錄集,因此你不能.EOF它。檢查受影響的行bu將一個變量作爲第二個參數傳遞給Execute。如果RowsAffected爲1,那麼就設置好了。

+0

您能舉一個例子嗎? – StealthRT