Sql分頁儲存過程以及實現

2021-05-24 10:33:06 字數 2342 閱讀 5060

建立乙個類檔案,內容如下:

using system;

using datahelper;

using system.data;

using system.data.sqlclient;

using system.web;

using system.configuration;

namespace classbase

set }

///

/// 表名

///

public string table

set }

///

/// 需要返回的列

///

public string fields

set }

///

/// 排序的欄位名

///

public string orderby

set }

///

/// 條件

///

public string where

set }

///

/// 每頁顯示的條數

///

public int pagesize

set }

///

/// 當前第幾頁

///

public int pageindex

set }

///

/// 0為順序,1為倒序

///

public int ordertype

set }

public string link

} #endregion

public paging()

public paging(string table,string fields,string orderby,string pkname,int pagesize,int pageindex,int ordertype,string where)

///

/// 返回分頁後的記錄

///

///

///

public datatable getlist(string url) ;

para[7].direction = parameterdirection.output;

datatable dt=new datatable();

dt=datahelper.sqlhelper.executedataset(getcon.constring,commandtype.storedprocedure,sql,para).tables[0];

sumcount=convert.toint32(para[7].value);//取得總記錄數

sumpage=(int)math.ceiling((double)sumcount/pagesize);//計算分成多少頁

int istart=pageindex-3;

int iend=pageindex+2;

if(istart<0) istart = 0;

if(iend>sumpage) iend =sumpage;

if(sumpage>1)

link+=string.format(npage,"");

link+=string.format(lpage,"");

link +=gourl; }

else if(this.pageindex == sumpage)

//link+=string.format(npage,"");

//link+=string.format(lpage,"");

link +=gourl; }

else

link+=string.format(npage,"");

link+=string.format(lpage,"");

link +=gourl; }

link [url=mailto:+=@]function">+=@""; }

return dt; }

} }

建立乙個wen窗體,該窗體擁有一控制項repeater ,乙個 label,在 .cs頁面新增乙個方法,方法如下:

private void binddata()

else

dt.dispose(); }

在page_load進行呼叫

if(!page.ispostback)

到此分頁成功

sql 儲存過程分頁

create proc myx prpagerecordset querystr nvarchar 1000 keyfield nvarchar 200 pagesize int,pagenumber int as begin declare sqltext as nvarchar 4000 dec...

SQL 儲存過程 分頁

1.俄羅斯儲存過程 的改良版 create procedure pagination1 pagesize int,頁面大小,如每頁儲存20條記錄 pageindex int 當前頁碼 as set nocount on begin declare indextable table id int id...

SQL 分頁儲存過程

create procedure splitpage sql nvarchar 4000 不帶排序語句的sql語句 page int,頁碼 recsperpage int,每頁容納的記錄數 id varchar 255 需要排序的不重複的id號 sort varchar 255 排序欄位及規則 as...