Exception in LIKE request using DataTable

My input: '[CL' I miss the closing parenthesis. And the columns contain "[CL]". I use a similar query for a fine in the "MYStps" column. But I get an exception. Below is an image.

{
    DataRow[] searchResult = MyDataTable.Select("MYStps Like '%" + txtSearchLog_Level.Text.Trim() + "%'");
}

Exception

+3
source share
1 answer

Because your text contains [, and this is a wildcard .

From LIKE (Transact-SQL)under "Using Wildcards as Literals"

You can use patterns matching patterns in the form of character letters. To use a wildcard as an alphabetic character, enclose the wildcard in brackets.

For instance:

Symbol       -- Meaning
LIKE '[[]'   -- [

[[]CL, .

[ [[], DataTable.Select, :

string s = txtSearchLog_Level.Text.Trim().Replace("[", "[[]");
DataRow[] searchResult = MyDataTable.Select("MYStps Like '%" + s + "%'");
+1

All Articles