Filtering a dataview

  • Thread starter Thread starter IndyChris
  • Start date Start date
I

IndyChris

I have DataView of DataSet. I want to filter the DataView by the date.
dvEvents.RowFilter = "BegDate >= '" + dateTimePicker1.Value.Date + "'
BegDate <= '" + dateTimePicker2.Value.Date.AddDays(1) + "'";

My problem is that the filter is getting the wrong values.
dateTimePicker1.Value = 8/2/2006
dateTimePicker2.Value = 8/3/2006

You would only expect records with 8/2 or 8/3 to show up. I'm getting
all records that are 8/2 and 8/2X.

How can I prevent the records that shouldn't be showing up from showing
up?

Thanks!
 
Indy,

You don't want to use a string representation. Rather, use '#' to
delimit your dates, like so:

dvEvents.RowFilter = "BegDate >= #" + dateTimePicker.Value.Date ...

Hope this helps.
 
Hi,

try:
dvEvents.RowFilter = "BegDate >= '" +
dateTimePicker1.Value.Date.ToShortDateString() + "'
BegDate <= '" + dateTimePicker2.Value.Date.AddDays(1)ToShortDateString() +
"'";

Why you have two datetimepickers? if so the upper bound should be compared
to dateTimePicker2.Value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top