Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am trying to perform a search for this string
! @ # $ % ^ & * ( ) '

then i used the sql syntax
SQL
Select ID From Tasks Where task LIKE '[!] [@] [#] [$] [%] [^] [&] [*] [(] [)] ''%'

but i dont get any result, any help
Posted

1 solution

Probably you want:
SQL
SELECT ID FROM Tasks WHERE task LIKE '! @ # $ \% ^ & * ( ) ''%' ESCAPE '\'


"in the database, the data in the field is Today's Task"

Check again - I just created a SQLite DB, with a table Tasks and three entries:
ID(int) Task(nvarchar(50)
1	Hello
2	Today's Task
3	XX Today's Task XX
NULL	NULL

Then I hacked some C#:
C#
string strCon = @"data source=D:\Temp\TestingSQLite.sldb";

SQLiteConnection con = new SQLiteConnection(strCon);
SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Tasks WHERE task LIKE '%Today''s Task%'", con);
con.Open();
DataTable dt = new DataTable();
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
da.Fill(dt);
And got two rows: 2, and 3.

Check your data!
 
Share this answer
 
v2
Comments
Cool Smith 15-Feb-13 8:07am    
hello, so even in other text, i only need to escape the % wilcard. say for example i need to search for "these are some wildcars & ! !" without the quote
OriginalGriff 15-Feb-13 8:25am    
Yes - the only wildcards in SQLite LIKE comparisions are % and _ for "zero or more of any character" and "any single character" respectively, so they are the only ones you need to escape (except single quote, obviously!)
Cool Smith 15-Feb-13 9:29am    
thank you very much. so even if i do this '%@! @@ @# $ @% @^ @& @* @( @) ''%', it doesn't have any negative effects right
OriginalGriff 15-Feb-13 9:34am    
You might want to escape the "%" in the middle, but otherwise it's fine!
Cool Smith 15-Feb-13 9:44am    
thank you very much

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