惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
博客园 - 【当耐特】
量子位
有赞技术团队
有赞技术团队
Jina AI
Jina AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
C
Check Point Blog
B
Blog RSS Feed
M
MIT News - Artificial intelligence
H
Help Net Security
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
腾讯CDC

博客园 - symjie

每天学一点AS3.0(五)---声音的控制(5) 每天学一点AS3.0(四)---声音的控制(4) 每天学一点AS3.0(三)---声音的控制(3) 每天学一点AS3.0(二)---声音的控制(2) 每天学一点AS3.0(一)---声音的控制 Jquery json的超强组合 - symjie - 博客园 javascript分页程序 - symjie - 博客园 初试jquery制作一个简单的loading delegate——委派 - symjie - 博客园 Ajax.net和GridView交互 Ajax.net实现loading登陆的效果 - symjie - 博客园 Ajax.net+模态窗口的登陆简单例子 GridView自定义分页(vb) - symjie - 博客园 用下拉列表控制gridview的分页 DataView数据组件 (转) c#冒泡程序 Atlas学习笔记 getElementByTagsName和相关函数的学习 基于Ajax.net的验证
sql 分页
symjie · 2007-05-25 · via 博客园 - symjie

       今天在做基于ajaxpro分页的时候,发现如果按照前一篇文章所指示,和gridview交互很是不方便,于是就写了基于存储过程和DataTable的分页,主要是存储过程,我就把存储过程给出,其他的很简单,就不再列出

 1--分页存储过程
 2create procedure GetNews
 3(
 4  @type int,--文章的类型
 5  @pgs int,--页大小
 6  @pgn int--页码,页码为0为求总也数
 7)
 8as
 9declare @strsql nvarchar(500--执行的sql语句
10declare @zongshu int--纪录总数
11declare @yeshu int --总页数
12declare @strtemp int--临时变量
13if @pgn=0
14  begin
15     select @zongshu=count(*from LYNews where newstype=@type
16    if @zongshu<=@pgs
17        begin
18          if @zongshu=0
19
20                 set @yeshu=0
21            
22           else           
23             set  @yeshu=1             
24        end
25     else--如果@zongshu>@pgs那么开始计算分页,如果@zongshu%@pgs=0的话,就说明每页都是慢的,如果不是的话,那么将存在多余的占一页
26         begin
27          set @strtemp=@zongshu%@pgs  --如果@zongshu%@pgs=0的话,就说明每页都是满的,如果不是的话,那么将存在多余的纪录占一页
28           if @strtemp=0
29             
30                set @yeshu=@zongshu/@pgs
31            
32           else
33              begin
34                set @yeshu=@zongshu/@pgs+1--否则的话那么得在添加一页来显示多余的数据
35              end
36             set @strsql='select '+str(@zongshu)+' as zongshu, '+str(@yeshu)+' as yeshu'  --返回总页数和总纪录数
37          end   
38end 
39else 
40   begin
41    if @pgn=1
42      
43         set @strsql='select top '+str(@pgs)+'  * from Lynews where newstype='+str(@type)+' order by postdate desc'--返回第一页的纪录
44       
45    else
46     
47      set @strsql='select top '+str(@pgs)+' * from LyNews Where newstype='+str(@type)+' and postdate<(select min(postdate)  from (select top '+str((@pgn-1)*@pgs)+' * from  LyNews  where newstype='+str(@type)+' order by postdate desc ) as t) order by postdate desc'
48      
49   end
50exec (@strsql)
51go