Cascade Record & Image Deletes
The Delete CodeFirst we need to add the functions for the image deletes. I use the functions
from Marcellino Bommezijn’s
excellent tutorial on image deletes. These can be added to the page or—better
yet--in an include file. Find the UD delete SB and look for the comment in bold
grey type below. This is where we create the File Scripting Object
(FSO) that will handle the category image deletes, set variable values
for the path and image names for rs_categories, then call Marcellino Bommezijn’s
functions to delete any rs_categories image that exists. Find the edit connection line of the delete SB shown bold in the line
above—it’s the last line before the UD delete SB executes--and make some
space because here’s where the magic happens. Now that we’ve taken care of the Product_Categories image, we must nest
the repeat regions we created earlier and modify them to perform image
deletes. This allows us to employ our repeat regions to loop through the
rs_products and rs_versions tables and extract values for the image deletes.
Insert the opening “While Wend” statement from the rs_products repeat
region we created earlier. Before we delete our product images, however, we need to delete the rs_versions
images. Remember the rs_versions recordset we created above uses the rs_products(“P_ID”)
value to select related rs_versions records marked for deletion and extract
the image field values. So we add our rs_versions “While Wend” statement
immediately below the rs_products “While Wend.” Now that we have collected all the image values, we create our rs_versions
(FSO) and set variables for the image path and name values, and call Marcellino Bommezijn’s
functions to perform the file delete as above. Make sure you make the
modifications needed to pull image name values from rs_versions. If the
path to your version images is different you will need to change that
as well. Okay, now that we’ve taken care of the version images we close the rs_versions
nested loop and re-enter the rs_products loop to perform the rs_products
image delete. Again add the FSO and delete code. That’s all there is to it. The stock UD generated code deletes the rs_categories
record and the relationships we created in our access database cascades
the delete to related records in the Products and Versions tables. |
||
|
James Threadgill
James Threadgill has authored numerous tutorials on ASP and ASP.NET web development, published on such sites as the Dynamic Zones and MSDN Accademic Alliance. He co-authored the Sam's book Dreamweaver MX: ASP.NET Web Development.
James first began computer programming in 1995 while attending Alvin Community College. He completed a certificate of computer science program and an Associate of Arts degree at Alvin before going on to the University of Houston-Clear Lake where he was awarded a Bachelor of Science and a Master of Arts.
James publishes fiction, poetry, and visual arts under the name Wayne James. His fiction first appeared in Raconteur in 1995 and since has been published numerous times: in Hadrosaur Tales 5 and 7, Bayousphere, and in the Write Gallery e-zine. His poetry first appeared in the small press magazine Lucidity in 1996 and has been published numerous times since. His collection of fiction and poetry, When Only the Moon Rages, was released in 2000. Most recently his work appeared in Tales of the Talisman winter 2010 and spring 2011 issues. James currently attends graduate school at the University of Houston and owns and operates small web design and internet marketing firm, WWWeb Concepts, with his wife, Karen, in Houston, TX USA.
Comments
DMX 2004 and the Cascade delete
Firstly thank you for your tutorials, I am very grateful. I am going to give the Cascade Record and Images deletes a go and was wondering, using mx2004 has things changed any to make it a little easier to do this.
Regards
Kenny
RE: DMX 2004 and the Cascade delete
You are welcome, Kenny. I was quite ill when you posted, but I'm back now!
Cascading file deletes are pretty complex considering the loops required. I wouldn't expect DMX to make this sort of thing point and click anytime soon.
RE: RE: DMX 2004 and the Cascade delete
re " I wouldn't expect DMX to make this sort of thing point and click anytime soon."
I have found the MX Kollection from Interakt does just that.
regards
Kenny
You must me logged in to write a comment.