|
This tutorial
shows you how to delete multiple records in a table with the help of checkboxes.
Once in place, all you need to do is to check the checkboxes next to the
records you want to delete from the database, and click the Delete button
button near the end of your page.
Create a recordset that selects the Primary Key (usually this is the AutoNumber
field) of your database table and a field that will enable you to easily
identify which record is associated with the value from the Primary Key.
For example if I want to delete my tutorials, I would select the ID field
(which is the Primary Key) and the Title field for identification purposes.

Then, construct a table to hold the tutorial titles and checkboxes in
place, and make sure that the entire table is placed within a form. Showing
the ID is an option that has no consequence on what we are going to do.
Set the action of the form to point to another ASP page (page2.asp)
that will perform the actual deleting.
We will name the checkox as Checkbox for clarity's sake, and assign
to its Checked Value the AutoNumber ID field from our recordset. Then
add a repeat region to the <TR></TR> and select Show All Records.
Now save this page as page1.asp and move on to create another page
call page2.asp.
On this new page create a Command by selecting Command from the Data Bindings
pallete. We will be doing our batch delete using SQL set notation. Using
set notation will allow us to process a number of records (rows) in just
one statement.
As an example if we selected records with the ID of 1, 2, 5 and 7 as the
ones we want to delete, essentially we will be looking at an SQL like
this:
DELETE FROM Tutorials WHERE ID = 1 OR ID = 2
OR ID = 5 OR ID =7
Using set notation the same can be achieved using a much more elegant
form of SQL:
DELETE FROM Tutorials WHERE ID IN (1,2,5,7)
Notice also how SQL uses the parenthesis to denote the beginning and end
of a set, as well as the use of "IN" as comparator instead of "=".
Now that we have covered the basics of set notations let us proceed by
creating the delete Command using UltraDev. Below is a snapshot of the
completed Command Object Dialog. Note that I have used a variable call
varSelect and assigned to it a run-time value of Request.Form("Checkbox").
Make sure that varSelect is enclosed within a pair of parenthesis.
The final step would be to specify a page to redirect to after the batch
deletion has been performed. Just switch over to the HTML Source window
and type in the name of the page you wish to redirect to. You can leave
the HTML there as it is or delete them, but it makes no difference.

|