.Net筛选器BindingSource [英] .Net Filter BindingSource

查看:53
本文介绍了.Net筛选器BindingSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样过滤BindingSource的列:"column1 LIKE'%John%'" ,则该列上所有包含John的行都将返回.

If I filter a BindingSource's column like this: "column1 LIKE '%John%'", then all rows containing John on that column will return.

如何返回column1包含 [some text] John [some text] Doe 的所有行?

How to return all rows for which column1 contains [some text]John[some text]Doe ?

"column1 LIKE'%John%Doe'" 不起作用.

推荐答案

根据

通配符*和%可以互换使用像这样的通配符比较.如果该字符串在LIKE中子句包含*或%,字符应放在括号([]).如果括号在子句,每个方括号字符应用括号括起来(例如[[] 或者 []]).允许使用通配符模式的开始和结束,或在模式的结尾或开始模式.例如:

Wildcard Characters Both the * and % can be used interchangeably for wildcard characters in a LIKE comparison. If the string in a LIKE clause contains a * or %, those characters should be enclosed in brackets ([]). If a bracket is in the clause, each bracket character should be enclosed in brackets (for example [[] or []]). A wildcard is allowed at the start and end of a pattern, or at the end of a pattern, or at the start of a pattern. For example:

"ItemName喜欢的'产品'""

"ItemName LIKE 'product'"

像"*产品"一样的ItemName"

"ItemName LIKE '*product'"

像产品名称"一样的ItemName""

"ItemName LIKE 'product*'"

不允许在通配符中使用通配符字符串的中间.例如,不允许使用"te * xt".

Wildcard characters are not allowed in the middle of a string. For example, 'te*xt' is not allowed.

因此,您不能使用LIKE做您想要的事情.下一个最好的选择是获取字符串表示形式,并使用正则表达式对其进行解析以查找所需的文本.将会很慢.

Therefore, you can't use LIKE to do what you want. Your next best bet is to get the string representation and use a Regex to parse it looking for the text you want. That's going to be SLOW.

您可以这样做

column1 LIKE '%John%' AND LIKE %Doe%'

但是逻辑不同,可能不是您真正想要的.

but the logic is different and may not be what you really want.

编辑-已添加

您最好在服务器级别进行过滤,因为您的数据库可能在字符串中间支持通配符.我只是在我们的SQL Server上尝试过,它工作正常.(SQL Server 2005)

You might be better off doing the filtering at the server level, as your DB might support a wildcard in the middle of the string. I just tried it on our SQL Server and it works fine. (SQL Server 2005)

这篇关于.Net筛选器BindingSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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