过滤字符串问题 [英] filter string issue
问题描述
您好我正在尝试对绑定源进行过滤。 之前我已经构建了很多过滤字符串,直到现在我才遇到问题。
Hello I am trying to do a filter on a binding source. I've built many filter strings before and I've never had an issue until now.
目前我实现了一项功能,允许用户右键单击数据网格查看字段并将单元格的内容添加到过滤器。
Currently I implemented a feature that allows a user to right click on a data grid view field and add the contents of the cell to the filter.
例如,单元格中有一些文本"IMPORTER,THE" 请注意最后一个字母'E'后的
空格。
For example there is some text in a cell "IMPORTER, THE " Please note the space after the last letter 'E'.
当我进行过滤时,过滤字符串如下所示: " DepartmentHeadName LIKE'IMPLORTER,THE''"。
When I do the filter the filter string looks like this: "DepartmentHeadName LIKE 'IMPORTER, THE %'".
过滤器从datagridview中删除所有内容。 如果我在E之后删除空格,那么过滤器可以正常工作并过滤所有单元格,并使用"IMPORTER,THE"
The filter removes EVERYTHING from the datagridview. If I remove the SPACE after the E then the filter actulaly works and filters on all cells with "IMPORTER, THE"
这对我来说没有意义,因为实际上有一个所有这些单元格中的空间,为什么过滤器表现得很奇怪,当我删除空格时会有效?
This does not make sense to me because there is actually a space in all of these cells so why is the filter behaving strangely and work when I remove the space?
任何想法?
推荐答案
绑定源将过滤委托给其数据源,这可能是一个依赖于正则表达式来解析过滤字符串的DataSet。
The binding source delegates the filtering to its data source, which is probably a DataSet that rely on regular expression to parse the filter string.
我建议您通过使用where子句再次查询数据库来在数据库中执行过滤以获得最佳性能,或者查询in-内存DataSet通过LINQ。如果您需要有关编写数据库访问代码的更多帮助,请尝试使用ADO.Net论坛。
I suggest you to do the filter in database for best performance by querying the database again with a where clause, or query the in-memory DataSet via LINQ. If you need more help on writing database access code, try the ADO.Net forums.
这篇关于过滤字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!