Eric's Ultra Efficiency Data Patement (Illustration + Code)

xiaoxiao2021-03-06  53

Data table structure:

Megaid Int Identity (1, 1) Not Null Primary Key Clustered

MegaGuid Char (36) Not Null Index

Data generating script: declare @i int set @i = 1 while @i <1000001 begin insert @i <1000001 begin insert @i <1000001 begin insert @i <1000001 Begin Insert Into Megatable (MegaGuid) VALUES (newid ()) set @i = @i 1 end Go

C # code:

DateTime StartTime;

Void Page_init (Object Sender, Eventargs E) {StartTime = DATETIME.NOW;}

Protected Override Void Render (HTMLTextWriter Writer) {base.Render (Writer); Response.write ("DateTime.now - StartTime);} int records = 10000; int pages = 10; int Pagesize = 15; SqlConnection conn = new SqlConnection ("Server = (local); database = megadata; user ID = sa; password = xxx");

Void Page_Load (Object Sender, Eventargs E) {if (! ispostback) {DGBIND (Getsqlstring (1));

int firstPage = int.Parse (hidFirstPage.Value); pnlButtons.Controls.Add (getPager (firstPage)); lblPrompt.Text = "data extraction range: SELECT TOP" records.ToString () "megaid FROM megatable Order by megaguid ";

String getsqlstring (int selectedPage) {string [] idsstray; string sqlstr;

IF (session ["idstr"]! = null) {IDSSTRARRAY = session ["idstr"]. Tostring (). split ('#');} else {sqlstr = "select top" records.tostring () " megaid FROM megatable ORDER BY megaguid "; SqlCommand cmd = new SqlCommand (sqlStr, conn); conn.Open (); SqlDataReader dr = cmd.ExecuteReader (); StringBuilder sb = new StringBuilder (" "); int n = 1;

While (DR.Read ()) {if (n% pagesize == 0) {sb.append (dr [0] .tostring () "#");} else {sb.append (dr [0] .tostring () ");} N ;} Dr.close (); conn.close (); sb.remove (sb.Length - 1, 1); idsstraray = sb.tostring (). Split ('#' ); Session ["idstr"] = sb.toString ();

hidPageCount.Value = idsStrArray.Length.ToString (); sqlStr = "SELECT megaid, megaguid FROM megatable WHERE megaid IN (" idsStrArray [selectedPage - 1] ")"; sqlStr = "ORDER BY megaguid"; return sqlStr; } Panel getPager (int firstPage) {int pageCount = int.Parse (hidPageCount.Value); Panel pnlPager = new Panel (); pnlPager.Controls.Add (new LiteralControl ( "
co" pageCount.ToString () "Page")); PNLPager.Controls.add (GetLinkButton ("FST", "Home", "PGBTN", "1")); PNLPager.Controls.Add (New LitralControl ("));

IF (FirstPage> 0) {pnlpager.controls.add (GetLinkButton ("pre", "front" pages.tostring () "page", "pgbtn", (firstpage - pages 1) .tostring ())) Pnlpager.controls.add (New LiteralControl ("));

For (int i = firstpage 1; i pagecount) {Break;} pnlpager.controls.add (getLinkButton (i.tostring (), "[" i. ToString () "]", "pgbtn", I.toTOString ())); pnlpager.controls.add (New LitralControl ("));}

IF (FirstPage Pages

Void DG_ItemDatabase (Object Sender, DataGriditeMeventargs E) {DG.Controls [0] .enableViewState = false;} ASPX code:

<% @ Import namespace = "system.text"%> <% @ import namespace = "system.data.sqlclient"%> <% @ Import namespace = "system.data"%> <% @ page language = "c #" %> < Title> Pager