c#中sql语句中传递Like参数的写法

string strSql = "select * from tbl_music where  musicname like '%@ii%'";//错误的
 
string strSql = "select * from tbl_music where  musicname like '%'+@name+'%'";//正确的

        SqlParameter[] p ={
            new SqlParameter("@name",SqlDbType.NVarChar)
        };
        p[0].Value = "爱";
        DataSet ds = DbHelperSQL.Query(strSql,p);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();

转载自:https://blog.csdn.net/duhongsheng/article/details/77250175

你可能感兴趣的:(.net开发)