C# Delete database records without SQL text?
-
Hi all, I need to delete rows from my db, when the criteria is: older than a certain date. Can it be done without an SQL string query?? Using only a DataSet and/or DataAdapter? The regular SQL would be: "DELETE FROM EventLog WHERE EL_TimeStamp<01/08/2006". But the problem is using the date in C# and Access-database. Thanks in advance, Danny
-
Hi all, I need to delete rows from my db, when the criteria is: older than a certain date. Can it be done without an SQL string query?? Using only a DataSet and/or DataAdapter? The regular SQL would be: "DELETE FROM EventLog WHERE EL_TimeStamp<01/08/2006". But the problem is using the date in C# and Access-database. Thanks in advance, Danny
Have you tried using a parameterized query?
DateTime dt = DateTime.Parse("01/08/2006"); // be careful about the current culture here, may want to specify
OledbCommand cmd = new OleDbCommand "DELETE FROM EventLog WHERE EL_TimeStamp < ?;", connection);
cmd.Parameters.Add("@p1", OledbType.Date,dt);
cmd.Execute();