vb.net bindingsource过滤器将日期转换为字符串

问题描述:

我正在使用过滤器中绑定源的a>方法。 NET来根据搜索框中的文本过滤DataGridView中的结果。但是,此搜索的想法是,如果任何单元格包含文本,则显示一行。所以我的过滤器字符串最终看起来像这样:

I'm using the filter method of Binding source in VB.net to filter results in a DataGridView based on the text in a search box. However, the idea of this search, is that it shows a row if any of the cells contain the text. So my filter string ends up looking like this:

filter = "ProductId LIKE '%" & searchterm & "%'" & " OR ScanDate like '%" & searchterm & "%'"

但是,当我尝试将过滤器放入filter属性时,它抱怨道,

However, when I try to put the filter in the filter property, it complains, saying that it cannot convert the date column to text for the comparison.

有没有办法告诉过滤器将日期时间单元格转换为字符串?

Is there a way to tell the filter to cast the datetime cells to string?

我正在考虑做的是在数据集中包含一个隐藏的列,其中包含日期的转换版本,我将告诉过滤器过滤那个

What I'm considering doing is having a hidden column in the dataset that contains a casted version of the date, and I'll tell the filter to filter that column.

这是我的分配代码:

bindingSource.Filter = filter 
dgv.DataSource = bindingSource.DataSource


我明白了,它有效

bindingSource.Filter = "ProductId LIKE '%" & searchterm & "%' OR Convert( ScanDate, 'System.String') LIKE '%" & searchterm & "%'"