I created a full-text catalog and I am trying to run a query on my database. Basically I have a list of vendors and I want the user to be able to type part of the name and get results. When I have more than one word in the search box I am getting an error. Here is my query
selectCMD.CommandText = "Select test1.vendorName, test2.address from test1, test2 where test1.ID = test2.ID and CONTAINS(VendorName, '%" & searchobj & "%') order by test1.ID"
I typed bio rad in the textbox and I recieve this error. How can I fix this query to except multiple words and not error out.
Syntax error occurred near 'rad%'. Expected ''''' in search condition '%bio rad%'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Syntax error occurred near 'rad%'. Expected ''''' in search condition '%bio rad%'.
Line 36: empDA.SelectCommand = selectCMD
Line 37: dbconn.Open()
Line 38: empDA.Fill(empDS, "test1")
Line 39: dbconn.Close()