您的位置:首页 > 数据库

C#通过SQL语句查询结果分页不用GridView的实现

2013-06-07 17:31 806 查看
假如我有100条记录,我想通过SQLserver 分段查询 让他 每页显示10条 显示10页,应该怎么写?

一:

select top 10 * from table where 主键 not in(select top 10*(页数-1) 主键 from table)

就是这样写啊 ,table就是你表的名字 主键就是表的主键字段啊, 页数应该是动态设定的,根据翻页来确定 页数,套着改。

二:

假设主键列为ID

select top 10 * from 表 order by id (第一页,前10条的)

后面每按一次下一页则,需要有一个递增数,来确定是第几页的~假设为a,第二页为1,第三页为2

select top 10 * from 表 where id not in(select top 10*a
id from 表 order by id)

这两个红色的要对应否则报错“Only one expression can be specified in the select list when the subquery is not introduced
with EXISTS.”

原文地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: