首頁  >  文章  >  資料庫  >  Access如何模糊参数进行分页查询代码

Access如何模糊参数进行分页查询代码

WBOY
WBOY原創
2016-06-07 16:22:351098瀏覽

具体代码如下: string sql = Select Count(ID) As rcount From TbProduct WHERE classID IN( + ids + ) AND PRODUCTNAME LIKE '%'+@ProductName+'%'; OleDbParameter[] sps = new OleDbParameter[1]; sps[0] = AccessDB.CreateParameter(@ProductName, OleD

   具体代码如下:

  string sql = "Select Count(ID) As rcount From TbProduct WHERE classID IN(" + ids + ") AND PRODUCTNAME LIKE '%'+@ProductName+'%'";

  OleDbParameter[] sps = new OleDbParameter[1];

  sps[0] = AccessDB.CreateParameter("@ProductName", OleDbType.VarChar, productName, 50, ParameterDirection.Input);

  int resultCount = (int)AccessDB.ExecuteScalar(sql, sps);

  recordCount = resultCount;

  if (resultCount >= 0)

  {

  if ((resultCount % pageSize) == 0)

  {

  pageCount = resultCount / pageSize;

  }

  else

  {

  pageCount = (resultCount / pageSize) + 1;

  }

  if (pageIndex == 1)

  {

  sql = "Select Top " + pageSize.ToString() + " * From TbProduct WHERE classID IN(" + ids + ") AND PRODUCTNAME LIKE '%'+@ProductName+'%' Order by ID desc";

  }

  else

  {

  int minRecord = (pageIndex - 1) * pageSize;

  sql = "Select Top " + pageSize.ToString() + " * From TbProduct Where ID Not In(Select ID From (Select Top " + minRecord.ToString() + " ID From tbProduct Where classID IN(" + ids + ") AND PRODUCTNAME LIKE '%'+@ProductName+'%' Order by ID desc )TemA) And classID IN(" + ids + ") AND PRODUCTNAME LIKE '%'+@ProductName+'%' Order by ID desc";

  }

  }

  else

  {

  pageCount = 0;

  }

  return AccessDB.ExecuteDataSet(sql, sps).Tables[0];

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn