程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Access數據庫 >> 關於Access數據庫 >> Access教程 如何模糊參數進行分頁查詢代碼

Access教程 如何模糊參數進行分頁查詢代碼

編輯:關於Access數據庫

       下面重點給大家介紹如何模糊參數進行分頁查詢的教程,接下來一起來看看制作的代碼吧!

      具體代碼如下:

      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];

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved