.Net 过滤器绑定源
如果我像这样过滤 BindingSource 的列:"column1 LIKE '%John%'"
,则该列上包含 John 的所有行都将返回。
如何返回 column1 包含 [some text]John[some text]Doe
的所有行?
“column1 LIKE '%John%Doe'”
不起作用。
If I filter a BindingSource's column like this: "column1 LIKE '%John%'"
, then all rows containing John on that column will return.
How to return all rows for which column1 contains [some text]John[some text]Doe
?
"column1 LIKE '%John%Doe'"
does not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 http://msdn.microsoft.com 上的文档/en-us/library/system.data.datacolumn.expression.aspx
因此,你不能使用 LIKE 来做你想做的事。您的下一个最佳选择是获取字符串表示形式并使用正则表达式来解析它以查找您想要的文本。那会很慢。
你可以这样做
,但逻辑不同,可能不是你真正想要的。
编辑 - 添加
您最好在服务器级别进行过滤,因为您的数据库可能支持字符串中间的通配符。我刚刚在我们的 SQL Server 上尝试过,效果很好。 (SQL Server 2005)
Per the documentation at http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
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.
You COULD do
but the logic is different and may not be what you really want.
Edit - added
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)
试试这个
try this