查找具有某些字符串的数据时出现问题

发布于 2024-12-09 20:32:07 字数 559 浏览 1 评论 0原文

我正在尝试完成这项工作,但不幸的是,它给了我以下错误

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热鲨 2024-12-16 20:32:07

% 和 * 在 LIKE 比较中可以互换使用通配符。

因此,您需要将这些字符括在表达式字符串中的方括号中,如下所示:

Name like '%testing : | / - “ ' & [*] # @%'

请参阅 DataColumn.Expression

从上面的链接:

通配符

* 和 % 可以互换用于通配符
在类似的比较中。如果 LIKE 子句中的字符串包含 * 或
%,这些字符应括在方括号 ([]) 中。如果有括号
在子句中,每个括号字符应括在
方括号(例如 [[] 或 []])。

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:

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 []]).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文