I am doing a program with c# and mysql database.
the task is actually taking 2 dates out from the mysql database and compare the 2 dates. if it is more than x days den the file will be deleted.
the following is the program that i have done but i am stuck at the logic that is compare the 2 days if more than x days delete the file.
string ConnectionString = "server=localhost;user id=name;password;persist security info=True;database=name of database;";
using (MySqlConnection conn = new MySqlConnection(ConnectionString))
{
MySqlCommand cmd = new MySqlCommand();
conn.Open();
if (conn.State == ConnectionState.Open)
{
cmd.Connection = conn;
cmd.CommandText = "select history ,lastclrhistorydate from table;";
cmd.CommandType = CommandType.Text;
MySqlDataReader reader;
reader = cmd.ExecuteReader();
if ((reader != null))
{
DataTable dt = new DataTable();
dt.Load(reader);
if (dt.Rows.Count == 1)
{
int history = int.Parse(dt.Columns[0].ToString());
string lastclrhistory =dt.Columns[1].ToString();
DateTime currentdate = DateTime.Now;
if ((currentdate - lastclrhistory) == history)
{
//(File.delete(file)
}
thank you

New Topic/Question
Reply




MultiQuote



|