0

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);
2
  • PLEASE DON'T SHOUT IN YOUR TITLE!!! Commented Aug 5, 2010 at 7:20
  • Sorry i dint mean for it to come across like that. Commented Aug 5, 2010 at 8:01

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
They are apparently.probably something in my settings then.But Thankyou for your help. I really appreciate it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.