Generate a SQL statement like a search engine

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

I'm looking for some code that would generate a SQL statement from a single
textbox in which a user could type in any number of words and quote-
enclosed phrases, just like Google or any other search engine. They won't
be using anything fancy like +, -, AND, OR, NEAR, etc. Just single words
and quote-enclosed phrases.

I'm sure some sample VB code like this exists somewhere, but I can't find
it. Could someone point me in the right direction?

Thanks,
Matt
 
Well why do you write it?

doesn't seem too difficult.

If you don't want and or or's then you are obviously going to just do an AND
I guess.

so for simple words
'get words into array
dim Words() as string=textbox1.text.split(" ")
dim sbSQL as new StringBuilder

sbSQL.append("SELECT (whatever, I don't know what) FROM sometable where
keyword in("
for sh as short=0 to Words.count-1
sbSQL.append(Words(sh))
if sh<>Words.Count-1 then sbSQL.append(",")
next sh

sbSQL.append(")")

Something like this would work...I am not in the IDE so don't hold me to the
syntax--this is all from memory--but very easy to do. No for the quotes you
would need to write code to get the quotes words out first I suppose.

HTH,

Shane
 
Back
Top