int number = 0;
if (curragePage > 1)
{
number = NUMCount * (curragePage - 1);
}
string strsql = "select top "
+ NUMCount + " * from Tb_Info where Infoid not in ( select top "
+ number + " Infoid from Tb_Info order by Infoid desc ) order by Infoid desc";
return GetTb_InfosBySql(strsql);
原来的 是 分页整个表。
我修改成 只要表里 catid=21的数据 来分页。
select top "
+ NUMCount + " * from Tb_Info where catid ="
+ catid + " and Infoid not in ( select top "
+ number + " Infoid from Tb_Info order by Infoid desc ) order by Infoid desc但是 只查询出来4个数据 就查不了了。请教 sql达人啊。
if (curragePage > 1)
{
number = NUMCount * (curragePage - 1);
}
string strsql = "select top "
+ NUMCount + " * from Tb_Info where Infoid not in ( select top "
+ number + " Infoid from Tb_Info order by Infoid desc ) order by Infoid desc";
return GetTb_InfosBySql(strsql);
原来的 是 分页整个表。
我修改成 只要表里 catid=21的数据 来分页。
select top "
+ NUMCount + " * from Tb_Info where catid ="
+ catid + " and Infoid not in ( select top "
+ number + " Infoid from Tb_Info order by Infoid desc ) order by Infoid desc但是 只查询出来4个数据 就查不了了。请教 sql达人啊。
解决方案 »
- 百分求助!c# 使用webbrowser控件问题,自动登录页面后,点新页面自动返回初始登录系统
- 伪静态后 aspnetpag无法翻页了?
- 在ASP.NET中上传文件必须使用FileUpload控件一个个上传吗?
- System.NullReferenceException: 未将对象引用设置到对象的实例
- 请教SqlCacheDependency问题,谢谢
- 样式表能这样用吗?
- 大家来解决一个问题____________________DropDownList1 的相关....知道的就来吧
- asp.net页面加百度搜索,免费代码含<from>,而asp.net不可以有两个<form>,怎么办?
- ASP.NET的页面提交时,有些控件回传了,有些没有,有什么规则么????学习编写控件想到的问题
- 问一个TreeView不能显示的问题.
- 打印隐藏内容
- 如何学好asp
2(
3 @PageIndex int,
4 @PageSize int
5)
6AS
7BEGIN
8 --定义三个变量:
9 -- @PageLowerBound :所取出记录的下限.
10 -- @PageUpperBound: 所要取出记录的上限.
11 -- @TotalRecords: 返回记录总数,主要用于页面的计算.
12 DECLARE @PageLowerBound int
13 DECLARE @PageUpperBound int
14 DECLARE @TotalRecords int
15
16 --计算上下限的值.
17 SET @PageLowerBound=@PageIndex * @PageSize
18 SET @PageUpperBound=@PageLowerBound+@PageSize-1
19
20--创建临时表:
21--IndexId是标识,自动增长1;
22--SimpleId由数据表[Simple]填充;
23 CREATE TABLE #PageIndexForSimple
24 (
25 IndexId int identity(1,1) NOT NULL,
26 SimpleId int
27 )
28--填充临时表
29 INSERT INTO #PageIndexForSimple(SimpleId)
30 SELECT s.[SimpleId]
31 FROM [Simple] s
32 --这里可以加WHERE condition和ODER BY语句
33
34 --取得记录总数,其实影响行数就是记录总数
35 SELECT @TotalRecords=@@ROWCOUNT
36
37 --获取我们所要的记录.
38 SELECT s.*
39 FROM [Simple] s,#PageIndexForSimple p
40 WHERE s.[SimpleId]=p.[SimpleId]
41 AND p.[IndexId]>=@PageLowerBound
42 AND P.[IndexId]<=@PageUpperBound
43 ORDER BY s.[Simple]
44
45 --返回记录总数.
46 RETURE @TotalRecords
47END 调用
Public List<Simple> GetSimple(int pageIndex,int pageIndex,out int totalRecords){
2 List<Simple> entity=new List<Simple>();
3 SqlParameter[]param=new SqlParameter[]{
4 new SqlParameter("@PageIndex",SqlDbType.Int),
5 new SqlParameter("@PageSize",SqlDbType.Int),
6 new SqlParameter("@ReturnValue",SqlDbType.Int),
7 };
8 param[0].Value=pageIndex;
9 param[1].Value=pageSize;
10 param[2].Direction = ParameterDirection.ReturnValue;
11 SqlDataReader reader=SqlHelper.ExecuteReader(CommandType.StoredProcedure, "GetSimple", param);
12 While(reader.Read()){
13 entity.Add(GetSimpleEntity(reader))
14 }
15 reader.Close();
16 try{
17 totalRecords=(int)param[2].Value;
18 }catch{}
19 return entity;
20}
+ NUMCount + " * from Tb_Info where Infoid not in ( select top "
+ number + " Infoid from Tb_Info where catid=21 order by Infoid desc ) and catid=21 order by Infoid desc";
select top "
+ NUMCount + " * from Tb_Info where catid ="
+ catid + " and Infoid not in ( select top "
+ number + " Infoid from Tb_Info where catid ="
+ catid + " order by Infoid desc ) order by Infoid desc
楼主漏了 not in里面加上条件了,
+ NUMCount + " * from Tb_Info where Infoid not in ( select top "
+ number + " Infoid from Tb_Info order by Infoid desc ) order by Infoid desc";是不是寫反了: 改成這樣試試:string strsql = "select top "
+ number + " * from Tb_Info where Infoid not in ( select top "
+ NUMCount + " Infoid from Tb_Info order by Infoid desc ) order by Infoid desc";