db query
-
Hi, I have a db table that has a date field for each record,say audate, that records the date and time when a particular record is added or updated. I want to list all the records that are added or updated in past two days... I wrote the query as.. q_str = " select * from tab1 where audate > " + System.DateTime.Now.AddDays(-2) + ""; But it gave me error that it could'nt resolve the query... How should I write my query... Thanks a lot..
-
Hi, I have a db table that has a date field for each record,say audate, that records the date and time when a particular record is added or updated. I want to list all the records that are added or updated in past two days... I wrote the query as.. q_str = " select * from tab1 where audate > " + System.DateTime.Now.AddDays(-2) + ""; But it gave me error that it could'nt resolve the query... How should I write my query... Thanks a lot..
After your line of code, q_str will contain "select * from tab1 where audate > 01/05/2005", this isn't valid SQL, the date part needs to escaped like:
q_str = " select * from tab1 where audate > """ + System.DateTime.Now.AddDays(-2) + """;
Even then depending on the database, you might need to format the date like YYYY-MM-DD.