经典ASP mysql INSERT获取结果关闭对象时不允许操作

时间:2012-05-21 22:40:50

标签: mysql asp-classic

我有这段代码:

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

我会在这里俯瞰什么?

更新

在这里找到我的答案! :O)

How to tell if a db update was successful?

2 个答案:

答案 0 :(得分:1)

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

  

如果是结果,则结果存储在新的Recordset对象中   行返回查询。如果是,则返回一个关闭的Recordset对象   不是行返回查询。

INSERT不是行返回查询,因此它返回一个已关闭的记录集,因此您不能.EOF它。检查受影响的行,将变量作为第二个参数传递给Execute。如果RowsAffected为1,则表示您已设置。

答案 1 :(得分:1)

两件事:

  1. 您将oRecordset定义为记录集,但随后使用&在newAdd
  2. 上查看eof
  3. 您为什么要尝试从插入查询中填充记录?