try an array and a loop:
string search = "hello world search";
cmd.CommandText= "select * from table1";
string sep = " where "
string[] terms = search.Split(' ');
for (int i =0; i < terms.length; ++i)
{
string pname = "@search" + i.ToString;
cmd.CommandText += sep + string.format("text like '%' + {0} +
'%'",pname);
cmd.Parameters.Add(pname, SqlDbType.NVarChar).Value = terms[i];
sep = " or ";
}
-- bruce (sqlwork.com);
"Howard" <ho*******@yahoo.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
How do I do this with parameterized query?
without parameterized query:
string search = "hello world search";
search = search.Replace(" ", " AND ");
SELECT * FROM TABLE1 WHERE TEXT LIKE '%' + @search + '%'
parameterized query:
SELECT * FROM TABLE1 WHERE TEXT LIKE '%' + @search + '%'
cmd.Parameters.Add("@search", SqlDbType.NVarChar).Value = search;
basically I am trying to perform a search where all the words in the
search string are present.
Howard