直播中
CREATE proc page
@pagenum int
as
SET NOCOUNT ON /*-----這一句很重要哦:)),不然它只會認 insert #change......這個數(shù)據(jù)集:))*/
declare @sql nvarchar(500) --聲明動態(tài)sql執(zhí)行語句
declare @pagecount int --當(dāng)前頁數(shù)
--取得當(dāng)前數(shù)據(jù)庫的記錄總數(shù)
declare @row_num int
begin
select @row_num=count(*) from cat_list
--創(chuàng)建臨時表,作為數(shù)據(jù)過濾
create table #change (T_id int)
--判斷當(dāng)前頁數(shù)
if @row_num>6 --大于頁面顯示記錄數(shù),則分頁
begin
set @row_num=@pagenum*6
if @row_num=6
select top 6 * from cat_list
else
begin
set @row_num=(@pagenum-1)*6
set @pagecount=@row_num
set @sql=N'insert #change (T_id) select top '+cast(@pagecount as char(100))+' T_id from cat_list where T_id not in (select T_id from #change)'
exec sp_executesql @sql
select top 6 * from cat_list where T_id not in (select T_id from #change)
end
end
else --只現(xiàn)實全部的數(shù)據(jù)
select * from cat_list
end
GO
客戶端這樣調(diào)用:
<!--#include file="conn.asp"-->
<!--#include file="adovbs.inc"-->
<% dim T_com
dim T_rs'declare datamanage recordset
dim parameters
set T_com=server.createobject("adodb.command")
T_com.ActiveConnection=conn
T_com.CommandText="page"
T_com.CommandType=adCmdStoredProc
'T_com.Prepared=true
set parameters=T_com.CreateParameter("@pagenum",adInteger,adParamInput)
T_com.Parameters.Append parameters
dim page
page=request.QueryString("page")
if page="" then
page=1
end if
T_com("@pagenum")=page
set T_rs=T_com.Execute
do while not T_rs.eof
response.Write T_rs("c_name")
T_rs.movenext
loop
%>
<a href="a.asp?page=<%=page+1%>">ddddd</a>