Reputation: 791
I have a search page, and i am trying to pull search terms from a query string, and search some text for that term using the LIKE SQl command. here's the code:
string searchTerm = "";
List<string> argList = new List<string>();
if (!String.IsNullOrWhiteSpace(Request.QueryString["searchTerm"]))
{
searchTerm = Request.QueryString["searchTerm"];
}
if (searchTerm != "")
{
argList.Add(searchTerm);
selectQueryString += "WHERE FullDescription LIKE '%@0%' ";
numOfArguments++; //increment numOfArguments by 1
}
queryResults = db.Query(selectQueryString, argArray);
If i run the page, it doesn't give me an error, but it says that it can't find any matches, even though i KNOW there are matches. As a test, i replaced the '%@0%' with '%villa%' and it works perfectly.
Maybe it's not recognizing @0 as a string?
Upvotes: 2
Views: 72
Reputation: 791
Turns out it was accepting the @0 as a literal. I finally found a way of seperating out.
'%' + @0 + '%'
Upvotes: 2