///
/// 獲取分頁資料
/// readtype: 1-資料列表,2-記錄總數,3-兩者
///
public static datatable getpagedlist(string connectionstring, ref int64 recordcount, int64 pagesize, int64 pageindex, string tablename, string keyname, string fieldname, string orderstring, string wherestring, int readtype)
;parms[0].direction = parameterdirection.output;
parms[1].value = tablename;
parms[2].value = keyname;
parms[3].value = fieldname;
parms[4].value = pagesize;
parms[5].value = pageindex;
parms[6].value = orderstring;
parms[7].value = wherestring;
parms[8].value = readtype;
datatable dt = sqlhelper.executedatatable(connectionstring, commandtype.storedprocedure, spname, parms);
recordcount = int.parse(parms[0].value.tostring());
return dt;
/*分頁儲存過程*/
if object_id('sp_getpagedlist','p') is not null
drop procedure sp_getpagedlist
gocreate procedure [dbo].[sp_getpagedlist]
@recordcount bigint output,--記錄總數
@tablename varchar(4000),--表名(必需)
@fieldname varchar(2000) = '*',--顯示字段
@pagesize bigint = 10,--每頁記錄數
@pageindex bigint =1,--當前頁
@orderstring varchar(200)='',--排序
@wherestring varchar(1000) = '',--where條件
@readtype int--1:資料,2:記錄數,3:兩者
asbegin
set nocount on
declare @beginrow bigint
declare @endrow bigint
declare @nsql nvarchar(4000)
declare @sql varchar(8000)
declare @whererow varchar(400)
declare @tmptablename varchar(255)
select @recordcount=0,@nsql='',@sql='',@whererow=''
if ltrim(rtrim(@fieldname))=''
set @fieldname='*'
if ltrim(rtrim(@orderstring))<>''
set @orderstring=' order by ' + @orderstring
if ltrim(rtrim(@wherestring))<>''
begin
if upper(left(ltrim(@wherestring),3))='and'
set @wherestring=' where 1=1 ' + @wherestring
else
set @wherestring=' where 1=1 and ' + @wherestring
endif @pagesize>0 and @pageindex>0
begin
set @beginrow = (@pageindex - 1) * @pagesize + 1
set @endrow = @pageindex * @pagesize
set @whererow = ' and (rowid between ' + convert(varchar(20),@beginrow) + ' and ' + convert(varchar(20),@endrow) + ') '
endset @tmptablename='#tmp_' + replace(convert(varchar(50),newid()),'-','')
set @sql = ' select rowid=identity(bigint,1,1), ' + @fieldname +
' into ' + @tmptablename +
' from ' + @tablename +
' where 1=1 ' + @wherestring + @orderstring
exec(@sql)
if (@readtype & power(2,0))>0
begin
set @nsql = 'select @recordcount = count(1) from ' + @tmptablename
exec sp_executesql @nsql,n'@recordcount int output',@recordcount output
endif (@readtype & power(2,1))>0
begin
set @sql = ' select * from ' + @tmptablename +
' where 1=1 ' + @whererow +
' order by rowid'
exec(@sql)
endif object_id('tempdb..' + @tmptablename, 'u') is not null
begin
exec('drop table ' + @tmptablename)
endend
go
分頁儲存過程 分頁儲存過程
分頁儲存過程 alter proc dbo p pageshow pagesize int,每頁大小 currentpage int out,當前頁 housename nvarchar 50 房產名稱 totalcount int out,總記錄數 totalpage int out 總頁數 as...
分頁儲存過程
create proc p sobigo percentpage tblname varchar 255 t category 表名 strgetfields varchar 1000 需要返回的列 fldname varchar 255 排序的欄位名 pagesize int 10,頁尺寸 pag...
分頁儲存過程
create procedure pro select pageindex int,pagesize int as select student.sno,student.sname,student.s grade.math,grade.physics,grade.huaxue,grade.chine...