Simple paging code

xiaoxiao2021-03-06  109

Public interface ipage (); DataTable nextpage (); DataTable page (int index);} ///

/// ORDERDETAILENTITY summary. /// public class OrdersEntity: IPage {private Hashtable pageIndexHsh = new Hashtable (); private int pageIndex = 0; public int PageCount {get {return this.pageIndexHsh.Count;}} public OrdersEntity () {// // Todo: Add constructor logic // string cmdstr = "Select {0} from {1} Order by {2} DESC"; cmdstr = string.format (cmdstr, Orders.primaryKeystring, Orders.tablename, Orders .PrimaryKeyString); SqlCommand cmd = new SqlCommand (cmdstr); Hashtable allHsh = new Hashtable (); int i = 0; using (SqlConnection sqlcn = AppGlobalVar.sqlConn ()) {cmd.Connection = sqlcn; sqlcn.Open (); SqlDataReader Dr = cmd.executeReader (System.data.commandbehavior.CloseConnection); While (Dr.Read ()) {Allhsh.Add (i, DR [0]); i ;} Dr.close ();} system.collections .Idictionaryenumerator IDE = allsh.GeteNumerator (); int pageIndex = 0; i = 0; while (IDE.MOVENEXT ()) {if (i == 0) {this.pageIndexhsh.add (pageIndex, ide.value); DEX ;} i ; if (i == appglobal.com} {i = 0;}} allsh.clear (); allsh = null;

}

Private DataTable FillPage () {string idstr = this.pageIndexhsh [pageindex] .tostring (); string opc = "select top {0} * from {1} where {2}> = {3}"; opc = string.format (opc, AppGlobalVar.AppRowsPerPage, Orders.TableName, Orders.PrimaryKeyString, idstr); SqlDataAdapter da = new SqlDataAdapter (opc, AppGlobalVar.sqlConn ()); DataSet ds = new DataSet (); da.Fill (ds, "PPC" ); Return DS.Tables ["PPC"];} public datatable firstpage () {this.pageIndex = 0; return this.fillpage ();} public datatable nextpage () {i (this.pageIndex == this.pageIndexhsh. Count-1) this.pageIndex = 0; this.pageIndex ; return this.FillPage ();} public int CurrentPageIndex {get {return this.pageIndex;}} public DataTable Page (int index) {this.pageIndex = index This is not very good: 1: Requires the primary key to perform a relatively small operation 2: No cache can be added to the following features should be improved:

------ Bush each already filled page data; ------ The amount of data is not possible to buffer all accessible data ------ Read the data SQL statement performance is not very good to have a list of recorded access frequencies, only the frequent page data of the cache is not known how to adjust the contradictions ... In addition: If there is a new record, after adding success Directly add new records to the buffer, which can make the record number does not match; in the contradiction. . . . . Which people have a better law, please specify it, thank you first

转载请注明原文地址:https://www.9cbs.com/read-97356.html

New Post(0)