how i can use like statement in c#
i am adding parameter by
qry = qry.Replace("{criteria}", "info.abc LIKE '%?val%'");
command not worked if i removed ' '
from the comma开发者_开发百科nd then it give a error how i can search the table in c#
As per the syntax of TSQL - Like you require to put search value between ' '
Example :
WHERE title LIKE '%computer%'
syntax
match_expression [ NOT ] LIKE pattern [ ESCAPE escape_character ]
Another way to do this which is more explicit - and in my opinion more readable because it avoids the crockety parts of the SQL syntax:
SqlDataReader r = new SqlCommand("SELECT * FROM the_table").ExecuteReader();
object[] values = new object[5000];
r.GetValues(values);
foreach (string value in values)
if (value.Length > 4)
if (value.Contains("val"))
new SqlCommand("UPDATE the_table SET value = 'newValue' WHERE "+
"value = '"+value+"'").ExecuteNonQuery();
精彩评论