vb.net bindingsource过滤器将日期转换为字符串 [英] vb.net bindingsource filter cast date to string

查看:192
本文介绍了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 & "%'"

这篇关于vb.net bindingsource过滤器将日期转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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