Last post Aug 14, 2015 06:16 AM by wmec
Aug 11, 2015 11:58 AM|Wael Asfour|LINK
Aug 11, 2015 12:44 PM|PatriceSc|LINK
Depends on your scenario. First I assume you already have a creation date or maybe an expiration date as you'll need to be able to select expired rows.
So you could just the same information to avoid showing expired rows. Or you could run a daily job to delete those rows (and I assume image files are tied to those rows?). Or you could call this deletion at strategic places inside your app (for example when
a user session starts).
I really depends which precision you need, which level of control you have on the hosting etc...
Aug 11, 2015 12:48 PM|Rion Williams|LINK
Generally it depends on how you are planning on running this.
If you wanted to run off of a Button Click event that would clean up everything from the past month, you could simply pull the current DateTime (via DateTime.Now) and clear out all records in the database that occurred (via some DateTime column) a month
using(var connection = new SqlConnection("Your Connection String"))
var query = "DELETE FROM YourTable WHERE YourDateProperty <= @DeletionDate";
using (var command = new SqlCommand(query, connection))
// Add your parameter (you could also use DateTime.Now.AddMonths(-1))
// Delete your records
Regarding files, it depends on how your database is set up. If you have the locations of images present in the database, you might pull a collection of your records first, delete every file related to those at their appropriate locations and then finish
up by deleting the database records themselves.
Aug 12, 2015 02:19 AM|Nan Yu|LINK
Hi wael ,
I want to delete a record from db after 30 days. How can I do that?
Also, how I can delete images from a folder after the same time?
You could explain more about your requirement , you could wrap the whole process inside a transaction ,and delete file from database
before deleting it from file system .If the process fails deleting from database, physical file won't be removed as you haven't reached file system delete logic. If the process fails deleting from file system you rollback transaction and database
operation is reverted. If successfully delete records from database ,then you could delete files like:
Aug 14, 2015 06:16 AM|wmec|LINK
1. Create scheduled task to delete image files
2. Call scheduled task to run Exe file, which will delete Database records.