查找具有某些字符串的数据时出现问题
我正在尝试完成这项工作,但不幸的是,它给了我以下错误
Error in Like operator: the string pattern '%testing : | / - “ ‘ & * # @%' is invalid.
只要它不包含上述字符串,该搜索就可以工作。这是我
DataRow[] rows = GetAllItems.Select("Name like '%" + cleanedText + "%'");
尝试过的搜索代码 - 根据 cHaos 进行修改(仍然虽然有错误)
string cleanedText = SearchText.Replace("\"", "\\\"").Replace("'", "''");
但当我在搜索中输入以下字符串时却没有运气,尽管我知道它在数据中
testing : | / - “ ‘ & * # @%
任何人都有一个很好的建议
谢谢
I am trying to make this work but have been unlucky it is giving me th following error
Error in Like operator: the string pattern '%testing : | / - “ ‘ & * # @%' is invalid.
This search works as long as it doesnt contain a string as the one above.. This is my code for the search
DataRow[] rows = GetAllItems.Select("Name like '%" + cleanedText + "%'");
I tried - Modified per cHaos (still errors though)
string cleanedText = SearchText.Replace("\"", "\\\"").Replace("'", "''");
but no luck when i enter the following string in the search although i know it is in the data
testing : | / - “ ‘ & * # @%
Anyone has a nice suggestion
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
% 和 * 在 LIKE 比较中可以互换使用通配符。
因此,您需要将这些字符括在表达式字符串中的方括号中,如下所示:
Name like '%testing : | / - “ ' & [*] # @%'
请参阅 DataColumn.Expression。
从上面的链接:
Both % and * can be used interchangeably for wildcard characters in the LIKE comparison.
As such you will need to enclose these characters in square brackets in your expression string like so:
Name like '%testing : | / - “ ‘ & [*] # @%'
See DataColumn.Expression.
From the above link: