Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string constr = @"Data Source=192.168.*.**; Database=wsditsupport; User ID=****; Password=*****";
            using (MySqlConnection con = new MySqlConnection(constr))
            {
                using (MySqlCommand cmd = new MySqlCommand("SELECT Date_Down FROM datalogin WHERE Date_Down < Date_Down(CURDATE(), INTERVAL 3 DAY"))
                {
                    using (MySqlDataAdapter sda = new MySqlDataAdapter())
                    {
                        cmd.Connection = con;
                        sda.SelectCommand = cmd;
                        if ((DateTime.Now - cmd).Days >= 3)
                        {
                            // Delete from database
                        }
                    }
                }


What I have tried:

This Code are my 1st try, but I need help?

I Need Help From you guys. if ((DateTime.Now - cmd).Days >= 3) <<< at this line I'm getting error Operator '-' cannot be applied to operands of type 'DateTime' and 'MySqlCommand'. So how to fix it?
Posted
Updated 19-Jun-16 22:45pm
v2

try
SQL
select * from datalogin  as mytable where datediff(now(), mytable.date) > 3
 
Share this answer
 
Just get MySQL to do the deletion at the same time as identifying the records to delete
C#
string constr = @"Data Source=192.168.*.**; Database=wsditsupport; User ID=****; Password=*****";
using (MySqlConnection con = new MySqlConnection(constr))
{
     using (MySqlCommand cmd = new MySqlCommand("delete from datalogin where datediff(now(), datedown) > 3;",con)
     {
          cmd.ExecuteNonQuery();            
     }
     con.Close();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900