Replies Back to Article
Delete Multiple Records and Associated Files
Excellent extension, however, if I have a database full of details where some people have and some people haven't uploaded images, the delete functions seems to stop whenever it comes across an empty image field.
If I try to run it on a table where an image field is always present it works just fine.
I know this is only a Beta version, but have you any ideas how I can work around this other than re-running the delete until all the records have gone? Thanks.
I haven't tested this, but it should do the job.
replace the code in the corresponding block with:
<%
Do While rsDel.EOF=False
dim TempPath
TempPath=(Server.Mappath(("YourSubfolder") &"/" & rsDel("Your DB__Field__with__File__Info")))
rsDel.Delete
if File.FileExists(TempPath)=1 then
File.DeleteFile(TempPath)
End if
rsDel.MoveNext
Loop
rsDel.Close
Set file="Nothing"
Set rsdel="Nothing"
else Response.redirect("Redirect__page_if__no__selection__made")
end if
Response.Redirect "Redirect__page_after__delete__action"
%>
Let me know if this helps and best regards,
Piero Mattirolo
Piero,
Thanks, this does now delete all the records in the table, but as soon as it comes across an empty image field it stops deleting the rest of the associated files.
What needs to be done to get the script to work with Javascript?
I am unfortunately inadequate for helping you with JavaScript. It would be stimulating to try but life is short and I would hate to keep you waiting:-)
Regards,
Piero
Thanks...the problem I'm having is with the Replace command. Apparently, vbscript & javascript handle them differently. I've checked with MS and haven't found a satisfactory answer. But I'll keep working on it. If I find a good answer, I'll let you know.
Paul
The following code works with Javascript:
<%
var strIDs = Request.QueryString.Item;
strIDs = strIDs.replace("&del=", ",");
strIDs = strIDs.replace("del=", "");
var DoDelete = Server.CreateObject("ADODB.Command");
DoDelete.ActiveConnection = MM_connCONNECTION_STRING;
DoDelete.CommandText = "DELETE FROM tbl_TABLE WHERE ID IN (" + strIDs + ")";
DoDelete.CommandType = 1;
DoDelete.CommandTimeout = 0;
DoDelete.Prepared = true;
DoDelete.Execute();
Response.Redirect("LINKEDPAGE.asp?");
%>
Thanks go to Zvika Gur-Esh, who helped me with the Javascript.
Hallo!
hope someone can help..
Selection page shows in the browser correctly also when I
create delete.asp and add server behaviour no errors.
The only thing is that nothin happens..i submit the form,seems working
fine but doesn't delete any record from table of accessdb..
This is the root on my local machine
C:
default.asp
selection.asp
delete.asp
\Connections
\db\preno.mdb
I put db as directory subfolder but i guess this is the problem...
What should i select as "Subfolder"??
Hope to hear from very much:-)
Ciaoo
Ema
You should make sure of the following:
1) that you have created a selection page and that this is submitting one or more record numbers. You can check this by setting the form submit method to GET and check in the URL bar what you have submitted. If this looks like
delete.asp?checkbox=23&checkbox=28
etc.
you should be all right. But also make sure that you that you request the value of something called checkbox as string parameter.
2) the Subfolder field should point to where you have your images, or the files referenced in the database, that you want to delete, not where you have put your database. The path to your database matters for your connection only. Actually I am wondering if you are deleting any record at all. This is the first thing you should start checking and therefore I humbly suggest that you check my tutorial on deleting multiple records:
Thanks for reply,I overchecked your tutorial and seems I followed all steps fine,but still not working.I don't have associated files to delete apart records in a table of preno.mdb,so I really can't guess what to write in subfolder..
Also,in dwmx,the server behaviour shows a red '!' ...
\\Here what i see in the browser:\\
../selection.asp?checkbox=326&checkbox=331&Submit2=Elimina
\\Here code in delete.asp\\
<!--#include file="Connections/ultrapreno.asp" -->
<%
Response.Buffer=1
Dim strID,rsDel,File,sql
strID=Request("checkbox")
if strID <> "" then
Set File = CreateObject("Scripting.FileSystemObject")
Set rsDel= Server.CreateObject("ADODB.Recordset")
rsDel.ActiveConnection = MM_ultrapreno_STRING
sql="SELECT * FROM reservations WHERE ID IN "
sql=sql &"(" & strID & ")"
rsDel.Source = sql
rsDel.LockType = 3
rsDel.open()
%>
<%
Do While rsDel.EOF=False
dim TempPath
TempPath=(Server.Mappath(("") &"/" & rsDel("ID")))
rsDel.Delete
if File.FileExists(TempPath)=true then
File.DeleteFile(TempPath)
rsDel.MoveNext
Else
response.write "Error: no file found at the address " &"<B>" & Temppath & "</B>" &". The corresponding record was deleted."
Exit Do
End if
Loop
rsDel.Close
Set file="Nothing"
Set rsdel="Nothing"
else Response.redirect("calendar.asp")
end if
Response.Redirect "selection.asp"
%>
Thanks for your patience..
Ciaoo
Ema
Well, if you have no files to delete, then this is definitely not your extension. You should use a simpler extension, that you can find on this same site and is also Macromedia Approved:
http://www.dmxzone.com/showDetail.asp?TypeId=3&NewsId=2048
I hope this helps
Kenny