Click here to Skip to main content
14,635,895 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

Is there a record with a keyword of "the school"? If not, then that is your answer as to why there is no result.
   
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?
Rate this:
Please Sign up or sign in to vote.

Solution 2

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
select id from school  where keyword like '%school%'
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

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
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

just as a tip don't use the code below unless you want you database to be destroyed from SQL Injection.

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"
   
v4

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100