使用datepicker中的值过滤查询结果 [英] Filter query results with values from datepicker
问题描述
请帮助我,我整天都被困在这里!!
我想用两个日期选择器来过滤wpf datagrid的结果。我到目前为止的查询如下
MySqlConnection cs = new MySqlConnection(connectionSQL);
cs.Open();
DataSet ds = new DataSet();
MySqlDataAdapter da = new MySqlDataAdapter(选择*来自交易WHERE date BETWEEN''+ datePicker1.Text +''AND''+ datePicker2.Text +'',cs);
MySqlCommandBuilder cmd = new MySqlCommandBuilder(da);
da.Fill(ds);
this.dataGrid1.ItemsSource = ds.Tables [0] .DefaultView;
datepicker是否需要xaml中的任何绑定? DBase日期字段具有日期类型。
Please help me, I have been stuck on this all day!!
I am wanting to filter results of wpf datagrid using two datepickers. My query i have so far is as follows
MySqlConnection cs = new MySqlConnection(connectionSQL);
cs.Open();
DataSet ds = new DataSet();
MySqlDataAdapter da = new MySqlDataAdapter("Select * from Transactions WHERE date BETWEEN ''"+datePicker1.Text +"'' AND ''"+datePicker2.Text +"'' ", cs);
MySqlCommandBuilder cmd = new MySqlCommandBuilder(da);
da.Fill(ds);
this.dataGrid1.ItemsSource = ds.Tables[0].DefaultView;
Does datepicker require any binding in xaml? DBase date field has type of date.
推荐答案
您是否尝试将日期设置为格式化日期?
http:// dev。 mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function%5Fstr-to-date [ ^ ]
Have you tried setting the date as a formatted date?
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function%5Fstr-to-date[^]
MySqlDataAdapter da = new MySqlDataAdapter("Select * from Transactions WHERE date BETWEEN STR_TO_DATE('"+datePicker1.Text +"','%d,%m,%Y') AND STR_TO_DATE('"+datePicker2.Text +"','%d,%m,%Y') ", cs);
T.他是你在普通SQL中可能会做的事情。
我也注意到日期之间的日期都来自DatePicker1.Text ...是故意的吗?
This is what you would probably do in normal SQL.
I also noticed that both between dates are from DatePicker1.Text... was that intentional?
这篇关于使用datepicker中的值过滤查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!