模糊查询时预编译报错
string checkResult = rbtTiaojian.SelectedValue;
p=txtcontent.Text.Trim();
switch (checkResult)
{
case "1": strWhere = "u_sitNo=@p"; break;
case "2": strWhere = "u_Enterprise like %@p%"; break;
}
System.Data.SqlClient.SqlParameter parameters = new System.Data.SqlClient.SqlParameter("@p", p);
string strSql = "select u_id,u_Enterprise,u_UserName,u_EnterpriseType,u_Phone, u_RealName,u_Mobile, u_RegisterTime from Ec_UserInfo where " + strWhere;
DataTable dt = DbHelperSQL.Query(strSql, parameters).Tables[0];
ResultView.DataSource = dt;
ResultView.DataBind();
运行上面代码,checkResult为1时可以通过;checkResult为2时就会报错呢?求解答!!!
------解决方案--------------------
case "2": strWhere = "u_Enterprise like '%'+@p+'%'"; break;