QUERY ON DATES TO EXCEL USING C#
I was trying to make excel graphs using query in c# and I need to collect data for the last month. I am using the following code and its not giving any error but its not giving any result either.
Basicaly I have the data in excel sheets and using that data im making graphs.
First im geting the two dates and converting them to short string and then im matching the strings with the dates picked from excel in the short strong format.
If anyone could answer, I would really appreciate help.
Thankyou,
THE CODE:
// Get current date and time
DateTime dtx = DateTime.Now;
string Date = dtx.ToShortDateString();
// Calculating the last month's date (substracting days from current date.)
DateTime lastmonth= DateTime.Today.AddDays( -30 );
string Date2 = lastmonth.开发者_StackOverflow中文版ToShortDateString();
OleDbCommand objCmdSelect = new OleDbCommand(
"SELECT [Hour],(Format(Date, 'Short Date')) AS text_Date,[U_CSSR] FROM [" + excelSheets[j] + "] WHERE CI=" + id + " AND (Format(Date, 'Short Date'))BETWEEN "+ Date + " AND "+ Date2 + " ", objConn);
I think your WHERE clause is logically incorrect. it should be
... BETWEEN "+ Date2 + " AND "+ Date ...
The earlier date should come first.
BETWEEN a AND b is equal to: x > a and x < b.
精彩评论