views:

43

answers:

1

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.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);
A: 

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.

Nick
stil not working.
adeena
Then make sure (Format(Date, 'Short Date')) and ToShortDateString() use the same format as output, and that their results are comparable.I don't know your local settings to test.
Nick
They are apparently.probably something in my settings then.But Thankyou for your help. I really appreciate it.
adeena