Reputation: 57
I would like to filter my DataGridView by a date range which is listed below.
I have a ListBox with 2 items with start and end date. Start date on top, end date below in listbox.
ListBox
DataGridView with date column named 'DATE'
Note: all DateTime formats in my DataGridView and ListBox are dd/MM/yyyy
, example: 05/23/2013
Filter = "(DATE >= '" + lbSearchByTime.Items[0].ToString().Trim() +
"and DATE <= '" + lbSearchByTime.Items[1].ToString().Trim() + "')";
Filter = "(DATE >= '" + Convert.ToDateTime(lbSearchByTime.Items[0].ToString().Trim()) +
and "DATE <= '" + Convert.ToDateTime(lbSearchByTime.Items[1].ToString().Trim()) + "')";
These 2 codes does not work for me. Is it wrong format or something else? It does not have any change when perform filter by button_click.
Upvotes: 2
Views: 4516
Reputation: 57
if (lbSearchByTime.Items.Count == 2)
{
DateTime start = stringToDateTime(lbSearchByTime.Items[0].ToString().Trim());
DateTime end = stringToDateTime(lbSearchByTime.Items[1].ToString().Trim());
Filter = "(DATE101 >= #" + start + "# and DATE101 <= #" + end + "#)";
}
Upvotes: 1