| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 946 人关注过本帖
标题:在asp.net中利用sql2005实现数据的分页
只看楼主 加入收藏
WJbobo
Rank: 1
等 级:新手上路
帖 子:85
专家分:3
注 册:2008-4-10
结帖率:76.92%
收藏
 问题点数:0 回复次数:6 
在asp.net中利用sql2005实现数据的分页
   各位大哥大姐们,利用sql2005实现数据的分页,我搞了一晚上。写了个sql语句;可以简单的实现输入每页显示多少行和显示那一页得到数据,但是我想了很久也不能返回共有多少条记录,和共有多少页?各位谁请给我点思路吧!我在网上看了别人用存储过程写的分页。但他们将数据当作一个字段返回的。那在转换成表显示很麻烦的。所以麻烦各位了。要能返回共有多少条记录的,个多少页。简单的我已经可以做了。谢谢
搜索更多相关主题的帖子: 数据 asp 
2009-11-03 23:43
chenxiao2006
Rank: 2
等 级:论坛游民
威 望:1
帖 子:23
专家分:17
注 册:2009-10-31
收藏
得分:0 
create proc pro_note
@rowIndex int ,
@maxNumber int
 as
with page as
(select id,row_number() over(order by id) as rowindex from note)

  select note.* from note,page where note.id=page.id
 and page.rowindex between (@rowIndex+1) and (@rowIndex+@maxNumber)
2009-11-04 16:18
WJbobo
Rank: 1
等 级:新手上路
帖 子:85
专家分:3
注 册:2008-4-10
收藏
得分:0 
with page as  //
(select id,row_number() over(order by id) as rowindex from note)
2009-11-04 18:34
WJbobo
Rank: 1
等 级:新手上路
帖 子:85
专家分:3
注 册:2008-4-10
收藏
得分:0 
以下是引用WJbobo在2009-11-4 18:34:08的发言:

with page as  //
(select id,row_number() over(order by id) as rowindex from note)
with page as //这个是干嘛.
2009-11-04 18:34
WJbobo
Rank: 1
等 级:新手上路
帖 子:85
专家分:3
注 册:2008-4-10
收藏
得分:0 
这是我搞了很久写出来的,不是存储过程。是sql语句.帮我简化下

declare @page int --当前页
declare @count int --每页显示多少行数据
set @page=1
set @count=5
//查询回复表的回复内容主题为3的字段,以及回复人的个人资料
select a.replyid, a.topicid, a.forumid, a.uid, a.title, a.replytext,
a.replaytime AS messagetime, b.lastreptime, c.email, c.sex, c.photo,
c.ugrade, c.mysetting,
       c.newtime, c.lastlongetime, c.Integral
 from (select *,
row_number() over( order by replyid) as id from replies where topicid=3) as a
INNER JOIN
        dbo.topics AS b ON a.topicid = b.topicid INNER JOIN
        dbo.users AS c ON a.uid = c.uid
where a.id >@count*(@page-1) and a.id<=@count*(@page)
//显示共有多少条回复,和可分为多少页
select count(*)as psum,(count(*))/@count as page from replies where topicid=3
2009-11-04 18:39
chenxiao2006
Rank: 2
等 级:论坛游民
威 望:1
帖 子:23
专家分:17
注 册:2009-10-31
收藏
得分:0 
  with page as ?
   建立一张虚表
   
2009-11-10 11:04
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
用LINQ最舒服.呵呵

飘过~~
2009-11-10 12:52
快速回复:在asp.net中利用sql2005实现数据的分页
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019331 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved