ADO and SQL Question, please advise gurus

Results 1 to 2 of 2

Thread: ADO and SQL Question, please advise gurus

  1. #1
    DaveM Guest

    Default ADO and SQL Question, please advise gurus

    I have a problem that I have been pondering over the last day or so. When you (it happens to me atleast) use ADO to insert records into a database with the INSERT query statement I can never close out my objects (Recordset and Connection) without an error coming up. Take the following ex:<BR><BR>&#039connection established<BR>strSQL = "INSERT INTO myTable(field1, field2, field3)"<BR>strSQL = strSQL & "VALUES(&#039val1&#039, &#039val2&#039, &#039val3&#039)"<BR>Set objRS = objConn.Execute(strSQL)<BR><BR>Response.Write "Thanks for updating"<BR><BR>objRS.Close<BR>Set objRS=nothing<BR>objConn.Close<BR>Set objConn=nothing<BR><BR>This code will insert the records to the database but it still returns an error message that says something like "can&#039t do this if the objects are closed". It does this if I use:<BR><BR>objRS.Open strSQL, objConn, , adLockOptimistic<BR><BR>instead of the Execute method as well.<BR><BR>However, if I use the AddNew and Update methods of the recordset object it will update everything without an error message. If anyone has some insight on this I would appreciate it.

  2. #2
    Join Date
    Dec 1969

    Default RE: ADO and SQL Question, please advise gurus

    An action query such as insert ... does not generate a recordset, even though your syntax would make it seem that does.<BR><BR>An open followed by addnew and update DOES use the recordset, hence the lack of an error in that situation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts