Deleting Multiple Records using Checkboxes

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default Deleting Multiple Records using Checkboxes

    Hi

    I wonder if anyone could help, I am trying to create a multiple delete page
    using checkbox's and it just will not work, I keep getting the following error
    message in a browser:-

    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in
    query expression 'PRODUCT_ID IN ()'.

    /checkboxdeletepage1.asp, line 30

    I have included the code, I think it is something to do with line 26
    (delcom.Command.Text= "Delete......)

    Help on this would be much appreciated as I now have no hair left.

    Thanks



    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="Connections/connTrio.asp" -->
    <%

    if(Request("selectionbox") <> "") then delcom__RecordIDs =
    Request("selectionbox")

    %>
    <%
    Dim rs_checkbox
    Dim rs_checkbox_numRows

    Set rs_checkbox = Server.CreateObject("ADODB.Recordset")
    rs_checkbox.ActiveConnection = MM_connTrio_STRING
    rs_checkbox.Source = "SELECT * FROM COMMENTS"
    rs_checkbox.CursorType = 0
    rs_checkbox.CursorLocation = 2
    rs_checkbox.LockType = 1
    rs_checkbox.Open()

    rs_checkbox_numRows = 0
    %>
    <%

    set delcom = Server.CreateObject("ADODB.Command")
    delcom.ActiveConnection = MM_connTrio_STRING
    delcom.CommandText = "DELETE FROM COMMENTS WHERE PRODUCT_ID IN (" +
    Replace(delcom__RecordIDs, "'", "''") + ") "
    delcom.CommandType = 1
    delcom.CommandTimeout = 0
    delcom.Prepared = true
    delcom.Execute()

    %>
    <%
    Dim Repeat1__numRows
    Dim Repeat1__index

    Repeat1__numRows = 10
    Repeat1__index = 0
    rs_checkbox_numRows = rs_checkbox_numRows + Repeat1__numRows
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <form name="form1" method="post" action="">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th scope="col">ID</th>
    <th scope="col">Model</th>
    <th scope="col">&nbsp;</th>
    </tr>
    <%
    While ((Repeat1__numRows <> 0) AND (NOT rs_checkbox.EOF))
    %>
    <tr>
    <td><%=(rs_checkbox.Fields.Item("PRODUCT_ID").Valu e)%></td>
    <td><%=(rs_checkbox.Fields.Item("PRODUCT_MODEL").V alue)%></td>
    <td><input name="selectionbox" type="checkbox" id="selectionbox"
    value="<%=(rs_checkbox.Fields.Item("PRODUCT_ID").V alue)%>"></td>
    </tr>
    <%
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1
    rs_checkbox.MoveNext()
    Wend
    %>
    </table>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    </body>
    </html>
    <%
    rs_checkbox.Close()
    Set rs_checkbox = Nothing
    %>

    DeanoClarke Guest

  2. Similar Questions and Discussions

    1. delete mulitple records with checkboxes
      i have a recordset with a looped region and checkboxes each checkbox has the individual record id assigned to it my questions is what SQL command...
    2. Deleting multiple records
      Here's what I have... A table with 3 columns. Headings are (Name, Prayer Request, and Delete). A loop that goes through a Record Set and prints...
    3. Insert Records from checkboxes
      Hi, I would like to be able to insert multiple records into a database using checkboxes. A query is used to display the checkboxes. How can...
    4. Update multiple records using checkboxes
      Searched the NG but no luck. Im displaying records from an Access2000 db in a table. The table is within a form and each record(row) has a...
    5. Deleting Multiple Records selected by checkboxes
      I have tried in vain after using 2 books - Prof ASP 3.0 and the compplete Reference for DWMX and about 8 different tutorial sites on the web that...
  3. #2

    Default Re: Deleting Multiple Records using Checkboxes

    A Command will run when the page loads, so you need to place an IF statement
    around it and the Dim code so that it only runs when you execute the form or
    other process to Delete the item/s.

    I usually pass a variable such as Delete=True either in URL or from a Hidden
    form field.

    You also need to move the

    <%

    if(Request("selectionbox") <> "") then delcom__RecordIDs =
    Request("selectionbox")

    %>

    so it is just before the COmmand Delete, that way you can use the IF statement
    around them with effecting your recordset.

    You will also need to aim your Form at the same page.

    Originally posted by: DeanoClarke
    Hi

    I wonder if anyone could help, I am trying to create a multiple delete page
    using checkbox's and it just will not work, I keep getting the following error
    message in a browser:-

    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in
    query expression 'PRODUCT_ID IN ()'.

    /checkboxdeletepage1.asp, line 30

    I have included the code, I think it is something to do with line 26
    (delcom.Command.Text= "Delete......)

    Help on this would be much appreciated as I now have no hair left.

    Thanks







    CarlGrint Guest

  4. #3

    Default Re: Deleting Multiple Records using Checkboxes

    I am a complete newbie to all of the this, how do I code the If statement, variable and hidden field.

    :o
    DeanoClarke Guest

  5. #4

    Default Re: Deleting Multiple Records using Checkboxes

    Heres a sample of one file I have

    <% If Request("Action") = "DeleteDoc" AND Request("ContentID") <> "" Then %>
    <%

    if(Request("ContentID") <> "") then CmdDelDoc__varContentID =
    Request("ContentID")

    %>
    <%
    ' delete document
    set CmdDelDoc = Server.CreateObject("ADODB.Command")
    CmdDelDoc.ActiveConnection = MM_woodford_STRING
    CmdDelDoc.CommandText = "DELETE FROM website_content WHERE ContentID = " +
    Replace(CmdDelDoc__varContentID, "'", "''") + " "
    CmdDelDoc.CommandType = 1
    CmdDelDoc.CommandTimeout = 0
    CmdDelDoc.Prepared = true
    CmdDelDoc.Execute()

    %>

    <% Response.Redirect("")%>
    <% End If ' delete document %>

    For your Hidden field just add

    <input name="Action" type="hidden" id="Action" value="Delete" />

    to your form.

    Originally posted by: DeanoClarke
    I am a complete newbie to all of the this, how do I code the If statement,
    variable and hidden field.

    :o



    CarlGrint Guest

  6. #5

    Default Re: Deleting Multiple Records using Checkboxes

    Hello Again - Really sorry about this

    I have got further although when I select something to delete and click submit
    nothing happens. Here is the code:-



    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="Connections/connTrio.asp" -->

    <%
    Dim rs_checkbox
    Dim rs_checkbox_numRows

    Set rs_checkbox = Server.CreateObject("ADODB.Recordset")
    rs_checkbox.ActiveConnection = MM_connTrio_STRING
    rs_checkbox.Source = "SELECT * FROM COMMENTS"
    rs_checkbox.CursorType = 0
    rs_checkbox.CursorLocation = 2
    rs_checkbox.LockType = 1
    rs_checkbox.Open()

    rs_checkbox_numRows = 0
    %>
    <% IF Request("action") = "DeleteDoc" AND Request ("selectionbox") <> "" Then
    %>
    <%

    if(Request("selectionbox") <> "") then delcom__RecordIDs =
    Request("selectionbox")

    %>
    <%

    set delcom = Server.CreateObject("ADODB.Command")
    delcom.ActiveConnection = MM_connTrio_STRING
    delcom.CommandText = "DELETE FROM COMMENTS WHERE PRODUCT_ID IN (" +
    Replace(delcom__RecordIDs, "'", "''") + ") "
    delcom.CommandType = 1
    delcom.CommandTimeout = 0
    delcom.Prepared = true
    delcom.Execute()

    %>
    <% Respose.Redirect("")%>
    <% End If 'delete document%>
    <input name="Action" type="hidden" id="Action" value="Delete"/>
    <%
    Dim Repeat1__numRows
    Dim Repeat1__index

    Repeat1__numRows = 10
    Repeat1__index = 0
    rs_checkbox_numRows = rs_checkbox_numRows + Repeat1__numRows
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <form name="form1" method="post" action="/checkboxdeletepage1.asp">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th scope="col">ID</th>
    <th scope="col">Model</th>
    <th scope="col">&nbsp;</th>
    </tr>
    <%
    While ((Repeat1__numRows <> 0) AND (NOT rs_checkbox.EOF))
    %>
    <tr>
    <td><%=(rs_checkbox.Fields.Item("PRODUCT_ID").Valu e)%></td>
    <td><%=(rs_checkbox.Fields.Item("PRODUCT_MODEL").V alue)%></td>
    <td><input name="selectionbox" type="checkbox" id="selectionbox"
    value="<%=(rs_checkbox.Fields.Item("PRODUCT_ID").V alue)%>"></td>
    </tr>
    <%
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1
    rs_checkbox.MoveNext()
    Wend
    %>
    </table>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    </body>
    </html>
    <%
    rs_checkbox.Close()
    Set rs_checkbox = Nothing
    %>

    DeanoClarke Guest

  7. #6

    Default Re: Deleting Multiple Records using Checkboxes

    That is because you do not have a Hidden field called Action with a Value of
    DeleteDoc.

    Also, the Response.Redirect("") will need a page within the "" so the code
    moves you to a page once completed.

    CarlGrint Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139