注册 登录
编程论坛 ASP.NET技术论坛

在asp.net中利用sql2005实现数据的分页

WJbobo 发布于 2009-11-03 23:43, 965 次点击
   各位大哥大姐们,利用sql2005实现数据的分页,我搞了一晚上。写了个sql语句;可以简单的实现输入每页显示多少行和显示那一页得到数据,但是我想了很久也不能返回共有多少条记录,和共有多少页?各位谁请给我点思路吧!我在网上看了别人用存储过程写的分页。但他们将数据当作一个字段返回的。那在转换成表显示很麻烦的。所以麻烦各位了。要能返回共有多少条记录的,个多少页。简单的我已经可以做了。谢谢
6 回复
#2
chenxiao20062009-11-04 16:18
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)
#3
WJbobo2009-11-04 18:34
with page as  //
(select id,row_number() over(order by id) as rowindex from note)
#4
WJbobo2009-11-04 18:34
以下是引用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 //这个是干嘛.
#5
WJbobo2009-11-04 18:39
这是我搞了很久写出来的,不是存储过程。是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
#6
chenxiao20062009-11-10 11:04
  with page as ?
   建立一张虚表
   
#7
bygg2009-11-10 12:52
用LINQ最舒服.呵呵
1