In my model I have a string txtSearche
with the value coming from a textbox like :
"hello all friends"
How can I write my statement dynamic adding WHERE text LIKE '%Text%'
for each word additional? something like 3 times:
WHERE Text LIKE '%@Text%'";
This is my code:
string[] wordsFromTxtSearche = txtSearche.Split(' ');
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = @"SELECT * "
+ " FROM ForumThread "
+ " WHERE Text LIKE '%@Text%'";
cmd.Parameters.Add(new SqlParameter("@Text", txtSearche));
I suppose I need to do it with help of For loop but i don't know how. please help me