Full text index and parametrized query with asp.net
I've got a query builder that's been built in house which is using a full text index 开发者_JAVA技巧in order to perform description searches.
The query is built and parametrized and I was wondering the best way to encode the form field from the website in order to pass search strings such as:
- Covered by
- "red" near "yellow"
- red" fish
Thanks
If you want to use full text search you should use where clause with other specific functions ( not just = or like ).
@param1 will still be a string (nvarchar eventually); see here:
Querying SQL Server Using Full-Text Search
for example, you query in this way (from MSDN):
USE AdventureWorks2008R2;
GO
DECLARE @SearchWord nvarchar(30)
SET @SearchWord = N'performance'
SELECT Description
FROM Production.ProductDescription
WHERE CONTAINS(Description, @SearchWord);
about special chars and escaping them, just have a look here: SQL Server Full Text Search Escape Characters?
精彩评论