码迷,mamicode.com
首页 > 数据库 > 详细

SqlParameter关于Like的传参数无效问题

时间:2015-04-24 12:15:31      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

正确的写法(简洁版)

private void GetHandleData(string strKeyWord1, string strKeyWord2, string strKeyWord3)
{
  string strSql = "select top 10 * from VW_Bookinfo where bcode like @strKeyWord1 and contacttel like @strKeyWord2 and spuname like @strKeyWord3 order by tdate desc";

  SqlParameter[] param = new SqlParameter[]
  {
    new SqlParameter("@strKeyWord1", SqlDbType.NVarChar,50),
    new SqlParameter("@strKeyWord2",SqlDbType.NVarChar,50),
    new SqlParameter("@strKeyWord3", SqlDbType.NVarChar,50)
  };
  param[0].Value = "%" + strKeyWord1 + "%";
  param[1].Value = "%" + strKeyWord2 + "%";
  param[2].Value = "%" + strKeyWord3 + "%";

  DataTable dt = ExecuteDataTableSql(strSql, param);

  DLView.DataSource = dt;
  DLView.DataBind();
}

SqlParameter关于Like的传参数无效问题

标签:

原文地址:http://www.cnblogs.com/itdaocaoren/p/4452780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!