Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004

    Unanswered: using sql server n vb i get probelem

    hi every1
    i am using sql server and vb for my project.probelem occurs when i close a recordset opened for the deletion it gives me probelem ;dispalying message" operation cannot be performed when a record is closed" i dont understand y because it works right when i write same code for editing or adding purpose.
    so plz tell me y is it so?
    Code i write
    1 private sub delete()
    2 dim rec as new adodb.recordset
    3 qry="delete from table where id=1"
    4 qry,connection,adopendynamic,adlockoptimistic
    5 rec.close
    6 end sub
    it works correctly if line#6 is removed otherwise it gives error message
    "operation cannot be performed if record is closed"

  2. #2
    Join Date
    Mar 2004
    Try using the connection object instead for your delete query as follows:

    1 private sub delete()
    2 dim cn as new adodb.Connection
    3 set cn = new adodb.Connection
    4 cn.ConnectionString ="..." 'Write your connection string here
    5 cn.Open
    6 qry="delete from table where id=1"
    7 cn.Execute qry, adExecuteNoRecords
    8 cn.close
    9 set cn = Nothing
    10 end sub

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

Posting Permissions

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