按日期过滤Datagrid视图 [英] Filter Datagrid view by date

查看:63
本文介绍了按日期过滤Datagrid视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在使用vb.net Express版本.我有一个datagridview,其中装有来自访问数据库的数据.我的所有数据端都正常工作,将调用日期"列设置为日期时间,并按在我的应用程序中升序的日期顺序进行了排序.

我在表单上也有一个monthviewcalender,并希望按monthviewcalender中选择的日期过滤datagridview,以显示我在该日期可能有的约会.

我尝试将选定的日期填充到文本框中,并使用以下内容进行过滤:




Hello all,
I am using vb.net express version. I have a datagridview which is popuated with data from an access database. I have all the data side working ok with the "Call Date" column set as datetime and sorted in date order assending within my application.

I also have a monthviewcalender on the form and wish to filter the datagridview by the date selected in the monthviewcalender to show appointments i may have on that date.

I have tried to populate the selected date into a textbox and use the following to filter:




AppointmentsBindingSource.Filter = String.Format("[Call Date] Like '" & TextBoxDate.Text) & "*'"



这会导致错误.我尝试了许多不同的变体,例如:



This causes a error. I have tried many different variants like:

AppointmentsBindingSource.Filter = ("[Call Date] Like '" & MonthCalendar1.SelectionRange.Start) & "*'"



该列在访问中设置为datetime,在数据库浏览器属性中为system.datetime.

任何人都可以帮助这最后的一点代码.

在此先感谢

Rich



The column is set as datetime in access and is system.datetime in the database explorers properties.

Can anyone help with this last little bit of code.

Thanks In Advance

Rich

推荐答案

如果将MS Access用作数据库,则需要这样查询数据库:
If you use MS Access as database, you need to ask database like this:
SELECT Field1, Field2, Fieldn
FROM Table1
WHERE DataTimeField =  #DATE#



在MS SQL中:



In MS SQL:

SELECT Field1, Field2, Fieldn
FROM Table1
WHERE DataTimeField =  'DATE'



您看到区别了吗?



Do you see the difference?


这篇关于按日期过滤Datagrid视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆