Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

In a table there is a keyword column whose values is “school”. When I write “school” in textbox and search all columns related to this record are shown in gridview.But when I write “the school” it donot show any record

str = "select id from school  where keyword like '%" + TextBox1.Text + "%'";


What will be the query?

Thanks
Posted
Updated 10-Jan-12 7:59am
v2

Is there a record with a keyword of "the school"? If not, then that is your answer as to why there is no result.
 
Share this answer
 
Comments
3796068 10-Jan-12 14:17pm    
I have no record "the school" but i have "school" record.So my question is in "the school" school keyword is present so how to search it?
Hi,

Your query is right. there is no problem at all. result may not be come because of trimming of the textbox value.

please also check your commandstring in debug mode, what exactly your query look like.

It should be
SQL
select id from school  where keyword like '%school%'
 
Share this answer
 
v2
If I understood your question correctly, you've misunderstood the like keyword. It searches a portion of a string from a larger string. For example for sentence:
The school is over
finding %school% would match, but if the text is
School
then searching for %The school% won't match since it doesn't appear in the text
 
Share this answer
 
just as a tip don't use the code below unless you want you database to be destroyed from SQL Injection.

SQL
str = "select id from school  where keyword like '%" + TextBox1.Text + "%'";


this code will look in the keywords where the keyword contains "the school". If you want a solution that will find "school" in the keywords look into Full Text Index which would find "school" when you type "the school"
 
Share this answer
 
v4

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