Parsing a textbox for use in a SQL statement

How can I take the value of a textbox and parse out the indivdual words to use in a WHERE statement without having to result to having the user placing a special charater in between word?

 I'm pulling the text out and doing the data pull in my code behind VB.net page.

Thanks,

Ty

0
TBarton
10/14/2008 12:20:02 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

4 Replies
368 Views

Similar Articles

[PageSpeed] 8

 you can use the string.split method and specify your own delimiter. http://msdn.microsoft.com/en-us/library/system.string.split.aspx or you can use the string.replace method and replace spaces with whatever character you want to delimit the words in the textbox

0
rrmacman
10/14/2008 12:38:43 PM

Do you mean something like, the user enters the following in a text box

"metallica korn keane"

And you want to do a database search:

WHERE bandname = "metallica" OR bandname="korn" OR bandname="keane"?

If so, simply replace the space char with an ' OR ' and add an extra ' to the beginning and end and you have a ready-prepared SQL WHERE clause:

            string search = "metallica korn keane";
            search = search.Replace(" ", "' OR '");
            search = "'" + search + "'";

0
Mr
10/14/2008 12:42:34 PM

I think that is exactly what I want only AND instead of OR. I'll give it a try later tonight.

Thanks,

Ty

0
TBarton
10/14/2008 2:39:50 PM

Worked like a charm. Thanks Mr^B

Ty

0
TBarton
10/15/2008 5:12:32 AM
Reply: