Results 1 to 5 of 5

Thread: Deleting Records in Access

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    323
    I am having trouble deleting records from an Access database using the following code. There are 2 SQL statements.

    1 - Deletes the record indicated in the QueryString
    2 - Deletes all records where the length of one field is less than 3

    Here's the code
    Code:
    <%
    Dim cnn
    Dim rst
    Dim ConnectString
    Dim strSQL
    Dim strDelSQL
    
    Set cnn = Server.CreateObject("ADODB.Connection")
    Set rst = Server.CreateObject("ADODB.Recordset")
    
    ConnectString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & Server.MapPath("database/tickets.mdb")
    
    strSQL = "DELETE * FROM RRS_Tickets WHERE TicketID = " & Request.QueryString("Record")
    strDelSQL = "DELETE * FROM Tickets WHERE Len(Ticket_Number) < 3"
    
    cnn.Open ConnectString
    
    rst.Open strDelSQL, cnn, 2, 2
    rst.Close
    
    rst.Open strSQL, cnn, 2, 2
    rst.Close
    cnn.Close
    Set rst = Nothing
    Set cnn = Nothing
    
    Response.Redirect("Tickets.asp")
    %>
    Here's the error I'm getting
    Code:
    ADODB.Recordset error '800a0e78' 
    
    The operation requested by the application is not allowed if the object is closed. 
    
    ?
    Thank you for any help.
    If you think education is expensive, try ignorance.

  2. #2
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274
    You're pretty close.

    use
    Code:
    cnn.execute strDelSQL, , adcmdtext
    cnn.execute strSQL, , adcmdtext
    instead of
    Code:
    rst.Open strDelSQL, cnn, 2, 2
    rst.Close
    
    rst.Open strSQL, cnn, 2, 2
    rst.Close

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    323
    Thanks. What does the adcmdtext part mean?
    If you think education is expensive, try ignorance.

  4. #4
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274
    The adcmdtext is optional and means that you are passing a text string to execute the command. If you look in your ADO help, you'll find other options such as adCmdTable, adCmdUnkown...

    You can also apply those options when opening a recordset.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    323
    Thank you very much!
    If you think education is expensive, try ignorance.

Posting Permissions

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



Click Here to Expand Forum to Full Width