I've got a .NET control which reads data from a SQL database and displays it in a DataGridView. I use the DateTimePicker to filter the data between two dates. This works fine when I'm within the same month, for example 28. June - 30. June, but if I set 1. July as the end date then I get no data. Date is stored as datetime in the database. Do you know what could be wrong? Here is my code for the DateTimePicker when the value is changed.
private void dtpEndDate_ValueChanged(object sender, EventArgs e)
{
//dtpStartDate and dtpEndDate are my DateTimePickers
DateTime start = dtpStartDate.Value;
DateTime end = dtpEndDate.Value;
dateFilter = string.Format("([{0}] >= '{1}' AND [{0}] <= '{2}')", "Date", start, end);
dataTable.DefaultView.RowFilter = dateFilter;
}
Thanks for the help guys. This solved the problem:
private void dtpEndDate_ValueChanged(object sender, EventArgs e)
{
//dtpStartDate and dtpEndDate are my DateTimePickers
string start = Convert.ToDateTime(dtpStartDate.Value).ToString("yyyy-MM-dd HH:mm:ss.ff");
string end = Convert.ToDateTime(dtpEndDate.Value).ToString("yyyy-MM-dd HH:mm:ss.ff");
dateFilter = string.Format("([{0}] >= #{1}# AND [{0}] <= #{2}#)", "Date", start, end);
dataTable.DefaultView.RowFilter = dateFilter;
}