473,503 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Full-Text Search in VB code

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
3 15314
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3811
by: daking | last post by:
I'm trying to track down a Java performance issue, and believe it may be related to GC behavior. Quick background: j2se app server running Caucho Resin 2.1.12, on RHEL3 with Sun JDK 1.4.2_04,...
7
6216
by: alexcn | last post by:
I have the following query: SELECT dbo.tSymExch.exCode, dbo.tSymGrp.sgCode, dbo.tSymMain.smCode FROM dbo.tSymExch FULL OUTER JOIN dbo.tSymGrp ON dbo.tSymExch.exID =...
1
3173
by: onewebclick | last post by:
Is there a way to detect a browser cache is full using javascript or HTML thorugh a web page and inform the user to clear the cache to improve performance of the website. It looks like google's...
1
3451
by: Jimmy Chen | last post by:
Recently I've done a db2 backup and restore/recovery, but the process for recovering the database was different than what I thought to be. here is what I did: DB2 is set in online mode -...
2
5067
by: Lee | last post by:
I have two identical schema tables (one in a production library and another in a development library) and I need to be able to easily compare the data in them for errors and omissions. With...
9
2731
by: Aleksey Serba | last post by:
Hello! I have 24/7 production server under high load. I need to perform vacuum full on several tables to recover disk space / memory usage frequently ( the server must be online during vacuum...
11
8247
by: rh00667 | last post by:
hi all, i'm confused now. how i can get the full path of an application? if myapp is in a directory which belongs to PATH, argv gives me the first token of cmd line, and not the real path of...
4
18215
by: Brian D | last post by:
In MS SQL 2005 when you do a Full Backup does it also backup and truncate the transaction logs or do I need to back the transaction logs up separately? Thanks. Brian
1
2584
by: vivek samantray | last post by:
I have a query.When i try to create a index on one of the table the index gets created but when i take the output it stuill shows "TABLE ACCESS FULL" Please see below what i did QUERY ======...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.