Replies Back to Article
Multiple Delete of Records Part 1
Please note that the example can now be found under:
http://www.ultradev-asp.net/udzone_tutorials/multiple/delete/Default.asp
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.
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.
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
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.
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)?
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
%>
Ricardo,
Sorry, i can't see the difference in the code ?
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");
%>
Minor error in the code:
sesvar = sesvar.replace("RECORDID=", "");
Should be:
sesvar = sesvar.replace("RECORD1ID=", "");
Sorry about that.
Yes, it can be done in Javascript
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
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
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 !
can anyone advise on how to update more than 1 field...?
cheers'
ben...
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
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>
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 :)