开发者

how i can use like statement in c#

开发者 https://www.devze.com 2023-01-14 02:43 出处:网络
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 searc

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消