access下的分頁方案

2021-04-17 00:23:27 字數 3116 閱讀 7472

具體不多說了,只貼出相關原始碼~

using system;

using system.collections.generic;

using system.text;

using system.data;

using system.data.oledb;

using system.web;

public class adopager

public adopager(string dbpath)

m_conn = new oledbconnection(m_connstring);

}/**

/// 開啟連線

///

public void connopen()

/**

/// 關閉連線

///

public void connclose()

private string recordid(string query, int passcount)

passcount--;}}

return result.substring(1);

}/**

/// 獲取當前頁應該顯示的記錄,注意:查詢中必須包含名為id的自動編號列,若不符合你的要求,就修改一下原始碼吧 :)

///

/// 當前頁碼

/// 分頁容量

/// 顯示的字段

/// 查詢字串,支援聯合查詢

/// 查詢條件,若有條件限制則必須以where 開頭

/// 排序規則

/// 傳出引數:總頁數統計

/// 傳出引數:總記錄統計

/// 裝載記錄的datatable

public datatable executepager(int pageindex, int pagesize, string showstring, string querystring, string wherestring, string orderstring, out int pagecount, out int recordcount)

) tempvw ", querystring);

oledbcommand cmdcount = new oledbcommand(string.format(" select count(0) as recordcount from ", myvw, wherestring), m_conn);

recordcount = convert.toint32(cmdcount.executescalar());

if ((recordcount % pagesize) > 0)

pagecount = recordcount / pagesize 1;

else

pagecount = recordcount / pagesize;

oledbcommand cmdrecord;

if (pageindex == 1)//第一頁

from order by ", pagesize, showstring, myvw, wherestring, orderstring), m_conn);

}else if (pageindex > pagecount)//超出總頁數

from order by ", pagesize, showstring, myvw, "where 1=2", orderstring), m_conn);

}else

from order by ", pagelowerbound, "id", myvw, wherestring, orderstring), pageupperbound);

cmdrecord = new oledbcommand(string.format("select from where id in () order by ", showstring, myvw, recordids, orderstring), m_conn);

}oledbdataadapter dataadapter = new oledbdataadapter(cmdrecord);

datatable dt=new datatable();

dataadapter.fill(dt);

connclose();

return dt;}}

還有呼叫示例:

html**

<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default" %>

示例的codebehind**

using system;

using system.data;

using system.configuration;

using system.web;

using system.web.security;

using system.web.ui;

using system.web.ui.webcontrols;

using system.web.ui.webcontrols.webparts;

using system.web.ui.htmlcontrols;

using system.collections.generic;

public partial class _default : system.web.ui.page

}protected void page_load(object sender, eventargs e)

private int pageindex = 1;

private int pagesize = 20;

private int pagecount = -1;

private int recordcount = -1;

private void loaddata()

條記錄,每頁條,頁次/",recordcount,pagesize,pageindex,pagecount);

access下的分頁方案

具體不多說了,只貼出相關原始碼 using system using system.collections.generic using system.text using system.data using system.data.oledb using system.web public clas...

ACCESS高效分頁

由於access資料庫內沒有儲存過程一說.那麼實現它的分頁上效率問題一直都是麻煩事.下面一段 相當來說算了很高效的了.如果有什麼更好的方法,請多指教 謝謝 呼叫方法 string strsql select p.productid,p.proclassid,p.productname,p.profl...

Access分頁查詢

由於access資料庫內沒有儲存過程一說.那麼實現它的分頁上效率問題一直都是麻煩事.下面一段 相當來說算了很高效的了.如果有什麼更好的方法,請多指教 謝謝 呼叫方法 string strsql select p.productid,p.proclassid,p.productname,p.profl...