Replies Back to Article

Multiple Delete of Records Part 1

Example link has changed !
September 28, 2001 by Marcellino Bommezijn

Please note that the example can now be found under:

http://www.ultradev-asp.net/udzone_tutorials/multiple/delete/Default.asp

Doesnt work
October 16, 2001 by Stuart Chase

Could somebody post the code for default.asp page?  I get the following error

ADODB.Field error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/gvfforce/db/default.asp, line 106

 

It puts out the appropriate number of check boxes for the records I have, but I get that error.

RE: Doesnt work
October 17, 2001 by Marcellino Bommezijn

Your message means that your recordset isn't correct. Check if there are rsFields that don't exist in your current recordset that is defined. Also be sure that your value in the checkbox is set correct.

Problems
November 27, 2001 by Karl Degraa

Hi, I get the following error message when trying this out.

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3.
/AdvanceStanding/UniUnitPages/MultidelUpdate.asp, line 16

  • POST Data:
    Delete=UnspElect6&Delete=hello&Delete=get&Submit=Submit
  • If I click 2 check boxes, it says that it wants 2 parameters and so forth. It posts the data across so I am at a bit of a loss.

    Any help would be appreciated.

     

    Selecting the Checkbox
    March 25, 2002 by Jelle-Jacob de Vries

    Hoi,

    I keep getting the following message. "You did not select any items to delete" Does someone has an idea what i am doing wrong (checkbox definition)?

    Can this be done with Javascript?
    June 11, 2002 by Brian Weinstein
    My pages are all in Javascript.  Do you have the code examples with Javascript or is there an easy way to translate it over?  Thanks
    CORRECTION
    August 10, 2002 by Ricardo Diaz

    A little mistake in the code! here how it should be:

    <%@LANGUAGE="VBSCRIPT"%>
    <!--#include file="../Connections/connBinder.asp" -->
    <%
    Dim strDeleteChecked
    strDeleteChecked = Request.Form("Delete")

    If strDeleteChecked = "" Then
    Response.Write "You did not select any items to delete!"

    Else
    Set Command1 = Server.CreateObject("ADODB.Command")
    Command1.ActiveConnection = MM_connBinder_STRING
    Command1.CommandText = "DELETE FROM tbl_usuario WHERE IdUsuario IN (" & strDeleteChecked & ") "
    Command1.CommandType = 1
    Command1.CommandTimeout = 0
    Command1.Prepared = true
    Command1.Execute()

    Set Command1 = Nothing

    Response.Write Request("Delete").Count & " links(s) were deleted..."
    Response.Write "One moment, you will be redirected back"

    End If

     %>

    RE: CORRECTION
    August 11, 2002 by Marcellino Bommezijn

    Ricardo,

    Sorry, i can't see the difference in the code ?

     

    Here's how I did the multiple update of records...
    September 2, 2002 by Paul Hirst

    Works well!  I modified it to work for multiple update of records.  If there's a better way, please, let me know.

    This method presupposes using the same setup as the first page
    of a delete multiple records (http://udzone.com/ShowDetail.asp?NewsId=3369
    is similar in set-up).  This will insert multiple records into a table using
    a common ID for one of the inserts and the checkbox selected values for the
    other insert.  Don't forget to change the variable names (in CAPS).

    <%@LANGUAGE="JAVASCRIPT"%>
    <!--#include file="../Connections/connTABLE.asp" -->

    <%
    var strIDs = Request.QueryString.Item;

    <!-- Below is a session variable used to capture the ID of the selected
    record -->
    var sesvar = Session("RECORDID");

    <!-- Parses out the variable name, leaving only the value -->
    sesvar = sesvar.replace("RECORDID=", "");

    <!-- Parses out the tag values leaving a comma delimited list -->
    <!-- NOTE:  Be sure the name of the passed value matches what you parse
    out -->
    strIDs = strIDs.replace(/&RECORD2ID=/g, ",");
    strIDs = strIDs.replace(/RECORD2ID=/g, "");

    <!--Create Array for strIDs-->
    var tableInserts_array = strIDs.split(",");

    <!--Loop through the list and insert each record individually -->
    for (var loop="0;" loop < tableInserts_array.length; loop++){
    var DoInsert = Server.CreateObject("ADODB.Command");
    DoInsert.ActiveConnection = MM_connTABLE_STRING;
    DoInsert.CommandType = 1;
    DoInsert.CommandTimeout = 0;
    DoInsert.Prepared = true;
    DoInsert.CommandText = "INSERT INTO tbl_TABLENAME (RECORD1ID, RECORD2ID)
    VALUES (" + sesvar + "," + tableInserts_array[loop] + ");";
    DoInsert.Execute();
    }
    <!--send the user where you'd like them to go-->
    Response.Redirect("WHEREVER.asp");
    %>

    RE: Here's how I did the multiple update of records...
    September 2, 2002 by Paul Hirst

    Minor error in the code:

    sesvar = sesvar.replace("RECORDID=", "");

    Should be:

    sesvar = sesvar.replace("RECORD1ID=", "");

    Sorry about that.

     

    Prbl Selecting the Checkbox
    September 18, 2002 by tosca tosca
    RE: Can this be done with Javascript?
    September 19, 2002 by Olivier Golaz

    Yes, it can be done in Javascript

    see http://www.udzone.com/ShowDetail.asp?NewsId=3430

    RE: Example link has changed !
    October 3, 2002 by judy hsu

    Thank you very much for the tips. It is very nice of you.

    I need your help to get it work!!! I tried it, but I could not get it work.

    Questions:

    1. Do I have to do Recordset(Query)?

    2. I did  a command(delete)

    But it still did not work. Help!

     

    Thanks

     

    Unable to get to work
    October 14, 2002 by Leon Wilson

    I've done exactely as described....loads of time.....

    Command1.CommandText = "DELETE FROM updateTest  WHERE SCAT IN (" & strDeleteList & ") "

    it doesn't like this line.

    updateTest is my table name....

    any know issues?

    Regards

    Leon

    It doesn' work if the ID is not numeric!
    November 5, 2002 by Massimo M.
    RE: It doesn' work if the ID is not numeric!
    November 5, 2002 by Massimo M.
    Multiple insert
    December 12, 2002 by empty empty
    How would this work with multiple inserts?  essentially moving data from one table to another
    demo + completed pages
    July 12, 2003 by Marcellino Bommezijn

    The demo is on-line again and the completed pages (update + delete functionality) are available for download.

    Hope this helps everybody that had some trouble with getting this too work !

    updating more than 1 field
    July 20, 2003 by ben tilford

    can anyone advise on how to update more than 1 field...?

    cheers'

    ben...

    How about multiple delete of files as well?
    August 19, 2003 by Mat Burhouse

    Hi, great tutorial, it really helped me!
    I've adapted it slightly for an image gallery with an approval system - an administrator can either approve an image or delete it with checkboxes - your code for both tutorial parts is on the same page so either an images gets approved (a field is updated to become 'yes' or deleted.

    I just have one thing left to do and that's delete the associated image files.
    Any ideas or examples of how i would adapt the code to also delete associated images for those records?

    Thanks

    How do you update using an apostrophe????
    February 23, 2004 by Zeus Maverick
    Yowzers!! This code is great but the text field I want to update will often contain an apostrophe...which won't work with this.  When I enter an apostrophe in the text field and hit the update button, I get an error due to trying to pass a single apostrophe in my string.  If I enter a double apostrophe instead of a single one (' '), then the update page displays correctly and only one apostrophe is added to the database.  I have seen fixes for the apostrophe problem when using a single update page but how is it done when trying to pass the data to a second page like in this code????  When the working example is up and running, you can see this error by adding an apostrophe to the text field and then clicking the update button.  Any help would be greatly appreciated!!!! Thanks!!!
    Code for update multiples modified SQL
    December 5, 2004 by greg Orr

    I have tried a different method for multiple field updates unsuccessfully but It should work do not know why!!!

    <%@LANGUAGE="VBSCRIPT"%>
    <!--#include file="Connections/patmenu.asp" -->
    <%
    Response.Buffer = True

           'First, we need to get the total number of items that could be updated
           Dim iCount
           iCount = Request.Form("Count")

           'We need to obtain each Link and ID
           Dim strLink, strLink1, strLink2, strID

    Dim strSQL
    Dim Command1
    set Command1 = Server.CreateObject("ADODB.Connection")
    Command1.ConnectionString = MM_patmenu_STRING
    Command1.Open

    Dim iLoop
          
    For iLoop = 0 to iCount

         strLink = Request(iLoop & ".Link")
     strLink1 = Request(iLoop & ".Link1")
     strLink2 = Request(iLoop & ".Link2")
         strID = Request(iLoop & ".ID")
       
    strSQL = "Update tblmeals "
    strSQL = strSQL & "SET meal = '" & strLink & "',"
    strSQL = strSQL & "Diet = '" & strLink1 & "', "

    strSQL = strSQL & "Assist = "' & strlink2 & "' "
    strSQL = strSQL & " where Episode = '" & strID & "'"
    Command1.Execute strSQL
     
    Next

    Command1.Close
           Set Command1 = Nothing

           Response.Write "Records were updated ! One moment..."

    %>
    <html>
    <head>

    <meta http-equiv="Content-Type" content="text/html; charset="iso-8859-1"">
    <meta http-equiv="refresh" content="2;URL=Default.asp">
    </head>

    <body bgcolor="#FFFFFF" text="#000000" leftmargin="2" topmargin="25">
    <br>

    </body>
    </html>

    primary key = text
    October 25, 2005 by jb doria

    cud u help me pls, wat if the primary key is not numeric e.g text

    thnxs :) God bless i wud really appreciate ur help :)