利用儲存過程進行真分頁獲取資料

2021-09-18 07:40:49 字數 3883 閱讀 1480

html工作

1.  引用css檔案

2.  引用js檔案

3.  再table下面加乙個div,定義樣式pagination2

4.  js處理**

});}();

currentpage = 100;}}

function initload()

//載入配方**資料

function inventorycheck(currentpage) ,

success: function (data, textstatus) );

//迴圈繫結table html。

$("#tbodyformula").html(html);

//設定分頁

5.  後端接收**及處理**

public object getformulalist()

public partial class formula_page

///

/// 分頁後的當前頁資料

///

public system.collections.generic.listcurrentdata

///

/// 總個數

///

public int allcount

}public dataset getlist(int pagesize, int pageindex, out int recordsum, string strwhere)

6.   資料庫分頁獲取**(儲存過程)

/*修改描述:

新增了全部顯示記錄的功能

判別條件@pageindex=0

*/alter procedure [dbo].[up_getrecordbypage]

@tblname varchar(50),--表名

@fldname varchar(20)= null,--主鍵名    

@pagesize int = 10,--每頁的大小

@pageindex int = 1,--第幾頁               

@recordsum int output, --記錄數

@ordertype tinyint = 1,  --排序型別    1== asc(公升序)和  0==desc(降序):

@strwhere varchar(4000) = null --過濾條件

asset nocount on

declare @ssql nvarchar(4000)

set @pageindex=@pageindex+1

set @recordsum = 0

if @pageindex<0 set @pageindex=0

if (@strwhere is null or rtrim(@strwhere)='')

set @ssql = 'select @recordsum = count(*)  from [' + @tblname  + ']  ' 

else

set @ssql =  'select @recordsum = count(*)  from [' + @tblname  + ']   where ' + @strwhere  

--select @tblname

--select @ssql

--return

execute sp_executesql 

@ssql,

n'@recordsum  int output ',

@recordsum output

declare @ssort  varchar(100)

declare @ssignal varchar(10)

declare @smaxmin varchar(10)

if @ordertype = 1

begin

set @ssort = ' order by  ' +@fldname + ' asc'

set @ssignal = '>'

set @smaxmin = 'max'

endelse

begin

set @ssort = ' order by  ' +@fldname + ' desc'

set @ssignal = '<'

set @smaxmin = 'min'

end--select @ssort

--return

if (@pageindex = 0)

begin

if (@strwhere is null or rtrim(@strwhere)='')

set @ssql = 

'select * from [' + @tblname + 

+ '] ' + @ssort

else

set @ssql = 

'select * from [' + @tblname + 

+ '] where ' + @strwhere   + @ssort

endelse if (@pageindex = 1)

begin

if (@strwhere is null or rtrim(@strwhere)='')

set @ssql = 

'select top  '+cast(@pagesize as varchar) + ' * from [' + @tblname + 

+ '] ' + @ssort

else

set @ssql = 

'select top '+cast(@pagesize as varchar) + ' * from [' + @tblname + 

+ '] where ' + @strwhere   + @ssort

endelse

begin

if (@strwhere is null or rtrim(@strwhere)='')

set @ssql = 

'select top  '+cast(@pagesize as varchar) + ' * from [' + @tblname + 

+ '] where ' +@fldname +@ssignal +'  (select '+ @smaxmin +'(' +@fldname + ')

from (select top  ' + cast(@pagesize * (@pageindex-1) as varchar)  + ' ' + @fldname +'  from [' + @tblname + 

+ '] '+ @ssort+') as t)'  + @ssort

else

set @ssql = 

'select top '+cast(@pagesize as varchar) + ' * from [' + @tblname + 

+ '] where ' + @strwhere +'  and ' + @fldname + @ssignal + ' (select '+@smaxmin+'('+@fldname+')

from (select top  ' + cast(@pagesize * (@pageindex -1) as varchar)  + ' ' + @fldname +'  from [' + @tblname + 

+ ']  where ' +@strwhere  +  @ssort+' ) as t )'  + @ssort

endprint @ssql

execute(@ssql)

ROW NUMBER 真分頁 儲存過程

if exists select from sysobjects where name proc pages drop proc proc pages create proc proc pages tablename varchar 100 pagesize int,pageindex int,or...

SQL真分頁儲存過程

create proc dbo proc delete tablename varchar 50 id varchar 5000 asbegin declare strsql varchar 5000 declare sql varchar 4000 set sql select col repla...

利用儲存過程實現資料分頁

利用ms sql2000的儲存過程實現資料分頁讀取,可簡化讀取的資料量。本過程的優點在於,輸入的sql語句沒有限制條件,而且寫法和思路都很簡單明瞭。create procedure dbo pageshow sql varchar 8000 where語句 pagesize int 10,每頁的大小...