本文介绍了如何在两个datetimepicker之间过滤datagridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在两个datetimepicker之间过滤datagridview。
我正在使用c#和MySQL。
我有什么试过:
I want to filter datagridview between two datetimepicker.
I'm using c# and MySQL .
What I have tried:
private void ShowButton (object sender, EventArgs e)
{
String constring ="datasource=;port=;username;password=";
using (var conn = new MySqlConnection(constring))
{
BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "Convert(Date,'System.String') Between '%" + dateTimePicker1.Text + "%' AND '%" + dateTimePicker2.Text + "%' ";
dataGridView1.DataSource = bs;
}
}
推荐答案
bs.Filter = string.Format("Date Between #{0:yyyy/MM/dd}# And #{1:yyyy/MM/dd}#", dateTimePicker1.Value, dateTimePicker2.Value);
这篇关于如何在两个datetimepicker之间过滤datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!