您的位置:首页 > 数据库

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

2015-04-24 10:47 204 查看
[b]正确的写法(简洁版)[/b]

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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: