0

Hi,

I have a c# form in which I retrieve data from Access DB.
I have Two DateTimePickers so I could choose data between dates.
My problems is when I try to retreive data between 19/10/2010 and 12/12/2010 it gives me me data beyond 12/12/2010 but when I try to retreive data between 9/12/2010 and 12/12/2010 it works fine.

here's my query:

"select DateId, NiarDesc, ManagerId, RateText, QuantityVal, ActionID From tbl1_order
 where DateValue(DateId) between "'19/10/2010' and '12/12/2010'";

i also tried to do it with getting the dates form the datetimepicker:

"select DateId, NiarDesc, ManagerId, RateText, QuantityVal, ActionID From tbl1_order
 where DateValue(DateId) between "' + datepicker1.Value.ToShortDateString + '" +
" and '" + datePicker2.Value.ToShortDateString +"'";

It seems that it ignores the month value and considers only the day value.
Why this is happening?

Thanks,
Udi

Edited by udigold1: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by udigold1
0

Hi,

Try like this:

OleDbConnection con=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Shahan.COREI3\My Documents\DateRange.mdb");
            OleDbCommand command = new OleDbCommand("select * from tbl1_order where StartDate between #" + dateTimePicker1.Value.ToString().Split(' ')[0] + "# and #" + dateTimePicker2.Value.ToString().Split(' ')[0] + "#");   
            con.Open();
            command.Connection = con; 
            OleDbDataAdapter da=new OleDbDataAdapter(command);
            DataSet ds=new DataSet("Dset");
            da.Fill(ds);
            dataGridView1.DataSource =ds.Tables[0];
            con.Close();

Check this as well:

http://www.eggheadcafe.com/community/aspnet/88/10220599/data-between-two-dates.aspx

Shahan

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.