Click here to Skip to main content
16,017,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to filter [ this character in Textbox but it says

error in like operator: the string pattern '%[%' is invalid.


i am unble to use [] this character

What I have tried:

Try

            bs.Filter = "TTITLE like '%" + txtTsearch.Text + "%'"
            DataGridView1.DataSource = bs

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
Posted
Updated 14-Mar-23 4:19am
Comments
RedDk 6-Nov-21 17:05pm    
Formatting issues with this post have I. It's customary to capitalize leading characters in sentences. Let me start with that as a reason that noone is going to be able to judge whether the other appended code is grounded anywhere in reality as-is.

Look at your code.
How many 'T's does "Title" normally start with?

If your column is called "TTitle" then it's just odd. If it isn't ... that code won't work.

And '[' is a special character in filters: DataColumn.Expression Property (System.Data) | Microsoft Docs[^] - to enter one as a sting part, it needs to be doubled.
 
Share this answer
 
Comments
Member 14621280 6-Nov-21 21:40pm    
TTITLE is the column only,

bs.Filter = "TTITLE like '%[ ]" + txtTsearch.Text + "%'"
DataGridView1.DataSource = bs

Shall I use above code?
Member 14621280 7-Nov-21 1:23am    
but above code not working
OriginalGriff 7-Nov-21 2:18am    
Did you read the whole of what I said, or just the first bit?
Member 14621280 7-Nov-21 7:06am    
i am the beginner so couldn't understand what you are shared
OriginalGriff 7-Nov-21 7:35am    
"And '[' is a special character in filters: DataColumn.Expression Property (System.Data) | Microsoft Docs[^] - to enter one as a sting part, it needs to be doubled."
What part of this is difficult for you to understand?
If you want only single [, and use it as filter, you need to check if this character is present in string and add [ around every single bracket is used ], so final query will look like this:


bs.Filter = "TTITLE like '%[[]some text[]]%'"


This will filter text by:
[some text]
 
Share this answer
 
Comments
CHill60 14-Mar-23 12:48pm    
Which was pointed out in Solution 1 back in 2021
Member 15793732 14-Mar-23 15:20pm    
There is oly link to VS docu and nobody mentioned correct syntaxe for original question.
I did, but its way too deep in converstaion, this way - the forgetful self from the future - will find this much faster. Thank you top expert.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900