Forums
This topic is locked
Multiple delete & all associated files
Posted 16 Feb 2004 16:19:46
1
has voted
16 Feb 2004 16:19:46 Peter Kutschmann posted:
I have created a form that allows multiple delete using the check box. (Many thanks to Marcellino Bommezijn's tutorials). Deleting multiple records works perfectly.The problem is, all associated files must also be deleted. I have been using another one of Bommezijn's tutorial www.dmxzone.com/showDetail.asp?TypeId=2&NewsId=1938 but this script keeps deleting only the associated files of the first record.
Here is the code:
<% Dim strDeleteList
strDeleteList = Request.Form("Delete"
%>
<%
Dim rsPasteventImages__MMColParam
rsPasteventImages__MMColParam = "1"
if (Request.Form("Delete" <> "" then rsPasteventImages__MMColParam = Request.Form("delete"
%>
<%
set rsPasteventImages = Server.CreateObject("ADODB.Recordset"
rsPasteventImages.ActiveConnection = MM_MICCdatabase_STRING
rsPasteventImages.Source = "SELECT * FROM pasteventimages WHERE ID IN (" & strDeleteList & ""
rsPasteventImages.CursorType = 0
rsPasteventImages.CursorLocation = 2
rsPasteventImages.LockType = 3
rsPasteventImages.Open()
rsPasteventImages_numRows = 0
%>
Function newFileSystemObject()
set newFileSystemObject=Server.CreateObject("Scripting.FileSystemObject"
End Function
Function fileExists(aFileSpec)
fileExists=newFileSystemObject.fileExists(aFileSpec)
End Function
Dim aspfile,Imagepath1, ImagePath2
ImagePath1 = Server.MapPath("\images\pastevents"
ImagePath1 = ImagePath1 & "\" & (Thumbnail("_small",(rsPasteventImages.Fields.Item("image".Value)))
ImagePath2 = Server.MapPath("\images\pastevents"
ImagePath2 = ImagePath2 & "\" & (rsPasteventImages.Fields.Item("image".Value)
Dim ImageLibrary(1)
ImageLibrary(0) = ImagePath1
ImageLibrary(1) = ImagePath2
For Each aspfile In ImageLibrary
Set File = CreateObject("Scripting.FileSystemObject"
If fileExists(aspfile) Then
File.DeleteFile(aspfile)
End If
set Command2 = Server.CreateObject("ADODB.Command"
Command2.ActiveConnection = MM_MICCdatabase_STRING
Command2.CommandText = "DELETE FROM pasteventimages WHERE ID IN (" & strDeleteList & " "
Command2.CommandType = 1
Command2.CommandTimeout = 0
Command2.Prepared = true
Command2.Execute()
set Command2 = Nothing
Response.Redirect("e_ctrpanel_pastevents_confirm.asp"
End If
Why does it not loop to delete all associated files? Why only the first record only?
Replies
Replied 19 Feb 2004 21:26:50
19 Feb 2004 21:26:50 Matthijs Horsman replied:
i think your your deleting ALL the records in the first loop becaouse your using:
<pre id=code><font face=courier size=2 id=code>DELETE FROM pasteventimages WHERE ID IN (" & strDeleteList & " " </font id=code></pre id=code>
instead i think you should use
<pre id=code><font face=courier size=2 id=code>DELETE FROM pasteventimages WHERE ID = (" & strDeleteList & " " </font id=code></pre id=code>
replace "IN" with "="
let me know if it worked out..
Matthijs
----------------
<pre id=code><font face=courier size=2 id=code>DELETE FROM pasteventimages WHERE ID IN (" & strDeleteList & " " </font id=code></pre id=code>
instead i think you should use
<pre id=code><font face=courier size=2 id=code>DELETE FROM pasteventimages WHERE ID = (" & strDeleteList & " " </font id=code></pre id=code>
replace "IN" with "="
let me know if it worked out..
Matthijs
----------------