ACCESS高效分頁

2021-08-11 04:00:51 字數 2504 閱讀 8072

由於access資料庫內沒有儲存過程一說.

那麼實現它的分頁上效率問題一直都是麻煩事..下面一段**,相當來說算了很高效的了.

如果有什麼更好的方法,請多指教! 謝謝!

呼叫方法

string strsql = " select p.productid,p.proclassid,p.productname,p.proflag,p.datetime,p.productimage,c.proclassname,c.proclasskey,c.proclassdes from productinfo p  " +

" left join proclass c on p.proclassid=c.proclassid ";

string strshow = " productid,productname,datetime,productimage,proflag,proclassname,proclasskey,proclassdes ";

return classfile.accesshelper.executepager(pageindex, pagesize, "productid", strshow, strsql, strwhere, " productid desc ", out pagecount, out recordcount);

///

/// 分頁使用

///

///

///

///

private static string recordid(string query, int passcount)

passcount--; }

}m_conn.close();

m_conn.dispose();

return result.substring(1); }

}///

/// access高效分頁

///

/// 當前頁碼

/// 分頁容量

/// 主鍵

/// 顯示的字段

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

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

/// 排序規則

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

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

/// 裝載記錄的datatable

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

) tempvw ", querystring);

oledbcommand cmdcount = new oledbcommand(string.format(" select count(*) 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, strkey, myvw, wherestring, orderstring), pageupperbound);

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

oledbdataadapter dataadapter = new oledbdataadapter(cmdrecord);

datatable dt = new datatable();

dataadapter.fill(dt);

m_conn.close();

m_conn.dispose();

return dt; }

}

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...

高效分頁(高效 通用)

select row number over order by qty,empid as rownum,empid,mgrid,qty into salesrn from dbo.sales create unique clustered index idx rn on salesrn rownum...