按dateTimePicker过滤datagrid中的数据 [英] Filter data in datagrid by dateTimePicker
本文介绍了按dateTimePicker过滤datagrid中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天
我在sql数据库中有一张表,一个字段是[date],它的类型是日期,例如(id,[date],[event])
使用C#Windows窗体,我需要添加dateTimePicker和DataGrid
datagrid由db表填充
我需要通过dataTimePicker引入特殊日期来过滤网格中数据的方法.
感谢您的帮助
Good day
I have one table in sql database one field is [date] it''s type is date, for example (id,[date],[event])
using C# windows form I need to add dateTimePicker and DataGrid
datagrid is filling by db table
I need way to filter data in grid by introduction special date by dataTimePicker.
Thanks for help
推荐答案
朋友您好,
这可能对您有帮助...
从投诉中选择*,其中Convert(smalldatetime,Convert(varchar(10),Complaint_Date,103),103)在"+ Convert.ToDateTime(dtpFrom.Value).ToString(" MM/dd/yyyy)+"' '和''"+ Convert.ToDateTime(dtpTo.Value).ToString(" MM/dd/yyyy)+"'',cnn);
其中Complains是我的数据库表,而Complaint_date是DateTime列...
根据您的要求,请更改查询...
在这里,我按两个日期过滤了gridview.
其中dtpFrom,dtpTo是日期时间选择器...
并将前端日期时间选择器的自定义格式设置为"dd/MM/yyyy".
Hi friend,
this may help you...
select * from Complaints where Convert(smalldatetime,Convert(varchar(10),Complaint_Date,103),103) between''" + Convert.ToDateTime(dtpFrom.Value).ToString("MM/dd/yyyy") + "'' and ''" + Convert.ToDateTime(dtpTo.Value).ToString("MM/dd/yyyy") + "''", cnn);
Where Complains is my database table and Complaint_date is the DateTime Column...
According to ur requirement please change the query...
Here i m filtering the gridview by two dates.
Where dtpFrom,dtpTo are date time pickers...
and set in front end date time picker''s custom format as "dd/MM/yyyy".
试试这个链接:
http://social.msdn.microsoft.com/论坛/en-US/vbgeneral/thread/81ca9270-c9b9-492f-9313-f2d634583ee9 [使用datetimepicker过滤datagridview? [
Hi,
Try this links:
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/81ca9270-c9b9-492f-9313-f2d634583ee9[^]
Filter datagridview using datetimepicker?[^]
This may help you.
All the best.
-AK
这篇关于按dateTimePicker过滤datagrid中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文