By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

SQL Full-Text Search in VB code

P: n/a
I'm trying to execute a full-text query from a vb.net web application.

The problem I have is that in SQL Server, the syntax for a full-text
search is

SELECT *
FROM table
WHERE CONTAINS( *, ' "searchstring" ')

For whatever reason, VB won't run that search string unless I eliminate
the double sets of quotes:

SELECT *
FROM table
WHERE CONTAINS( *, "searchstring")

This will not work for a search phrase - only single words, and it also
will not work for a wild card:

SELECT *
FROM table
WHERE CONTAINS ( *, "search*")

The above does not work - I must assume that the double quotes are
needed for both wild card searches and exact phrase searches -

The problem of course is that in vb code the SQL string is already
enclosed in search quotes - the single quotes are then used to indicate
double quotes within the search.

I have tried using two single quotes on either side of the string, but
it doesn't seem to work. ie:

"SELECT * FROM table WHERE CONTAINS ( ' '" & textbox1.text & "' ')"

Does anybody have any ideas?

Trevor Fairchild

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
A: the SQL wildcard is % not * as in Access

B: SQL uses single quotes ' not double "

On 20 Nov 2003 18:50:36 GMT, Trevor Fairchild <ba*********@aol.com>
wrote:
I'm trying to execute a full-text query from a vb.net web application.

The problem I have is that in SQL Server, the syntax for a full-text
search is

SELECT *
FROM table
WHERE CONTAINS( *, ' "searchstring" ')

For whatever reason, VB won't run that search string unless I eliminate
the double sets of quotes:

SELECT *
FROM table
WHERE CONTAINS( *, "searchstring")

This will not work for a search phrase - only single words, and it also
will not work for a wild card:

SELECT *
FROM table
WHERE CONTAINS ( *, "search*")

The above does not work - I must assume that the double quotes are
needed for both wild card searches and exact phrase searches -

The problem of course is that in vb code the SQL string is already
enclosed in search quotes - the single quotes are then used to indicate
double quotes within the search.

I have tried using two single quotes on either side of the string, but
it doesn't seem to work. ie:

"SELECT * FROM table WHERE CONTAINS ( ' '" & textbox1.text & "' ')"

Does anybody have any ideas?

Trevor Fairchild

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Jul 20 '05 #2

P: n/a

"Trevor Fairchild" <ba*********@aol.com> wrote in message
news:3f*********************@news.frii.net...
I'm trying to execute a full-text query from a vb.net web application.

The problem I have is that in SQL Server, the syntax for a full-text
search is

SELECT *
FROM table
WHERE CONTAINS( *, ' "searchstring" ')

For whatever reason, VB won't run that search string unless I eliminate
the double sets of quotes:

SELECT *
FROM table
WHERE CONTAINS( *, "searchstring")

This will not work for a search phrase - only single words, and it also
will not work for a wild card:

SELECT *
FROM table
WHERE CONTAINS ( *, "search*")

The above does not work - I must assume that the double quotes are
needed for both wild card searches and exact phrase searches -

The problem of course is that in vb code the SQL string is already
enclosed in search quotes - the single quotes are then used to indicate
double quotes within the search.

I have tried using two single quotes on either side of the string, but
it doesn't seem to work. ie:

"SELECT * FROM table WHERE CONTAINS ( ' '" & textbox1.text & "' ')"

Does anybody have any ideas?

Trevor Fairchild

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


I would guess that you have an issue with escaping the different type of
quotes in VB. If you build the complete command in VB then print it, does it
have the correct SQL Server syntax? It's not completely clear from your post
if you've tried this. You may need one of the following (untested):

/* Simple phrase */
"SELECT * FROM table WHERE CONTAINS ( *, ' """ & textbox1.text & """ ')"
/* Single word */
"SELECT * FROM table WHERE CONTAINS ( *, '" & textbox1.text & "')"

Simon
Jul 20 '05 #3

P: n/a
I found the answer elsewhere.

Thank you, though.

I had to use Chr(34), which is the ASCII code for a double quote, to
force an insert of double quotes into the SQL string on either side of
the search criteria.

It should be noted that I could only get the * working as a wildcard - %
did not work in VB.NET.

The Full-Text syntax specifically stated that the search criteria was
double-quoted, and then the search string Plus the double-quotes were
then surrounded by single quotes (I do not know why):

This is what I had to do to get it working:

command.CommandText = "SELECT * FROM table WHERE CONTAINS ( ' " &
chr(34) & "mySearchHere" & chr(34) & " ' )"

This comes out looking like:

SELECT * FROM table WHERE CONTAINS( ' "mySearchHere" ')

And that is how the help in SQL Server 2000 showed it...

Thanks, everyone!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.