问题描述
你好,
我在dataGridview中从MS Access数据库中获取数据。
Am fetching the data from MS Access database in dataGridview.
我有一个按钮来加载数据之后,我想从datetimepicker中选择日期,在选择时,它应根据gridview中的选择显示所有记录。我试过这段代码...
I have one button to load the data in table after that I want to select the date from datetimepicker and on selection it should dispaly all the records based on the selection in gridview.I tried this code...
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
DataView dv = new DataView(dt);
DateTime startT = new DateTime();
DateTime endT = new DateTime();
startT = dateTimePicker1.Value.Date; // Ex: 2014-11-24 12:00:00
endT = dateTimePicker1.Value.Date.AddDays(1).AddSeconds(-1); // Ex: 2014-11-24 11:59:59
// dv.RowFilter = string.Format("Select * From CustomerDetails WHERE DATA Between '" + startT + "' AND '" + endT + "'");
dv.RowFilter = string.Format("BookingDate '%{0}%'", dateTimePicker1.Value.ToString());
dataGridView2.DataSource = dv;
//bindingSource1.Filter = string.Format("EventDate = #{0}#",dateTimePicker1.Value.ToLongDateString());
}
谢谢,
推荐答案
根据您的代码,我认为有两点意见检查。
Based on your code, I think there is two point to check.
1。我建议你查看"dateTimePicker1.Value.ToString()"的值和"BookingDate"的值,你需要保持它们的格式相同。
1. I suggest you check the value of the "dateTimePicker1.Value.ToString()" and the value of the "BookingDate", you need to keep the format of them the same.
2。对于DataView的RowFilter,您将错误的值传递给RowFilter,似乎您想使用like运算符,您可以参考以下链接:
2. For the RowFilter of the DataView, you passed a wrong value to the RowFilter, it seems that you want to use the like operator, you could refer the link below:
#DataView RowFillter like operator
#DataView RowFillter like operator
http://stackoverflow.com/questions/17313631/dataview-rowfillter-like-operator
最好的问候,
Best Regards,
Edward
这篇关于从datetimepicker控件更改日期时过滤日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!