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

正确的写法(简洁版)

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。