这是个典型的top分页查询
@currentpageindex 就是gridview的current page indexUSE northwindALTER PROCEDURE [dbo].[GetProductsByPagenum]
(
@pagesize int = 5,
@currentpageindex int=1,
@rowcount int output
)
AS
/* SET NOCOUNT ON */
select @rowcount=count(*) from Products select top (@pagesize) *
from Products
where ProductID not in (select top (@pagesize*@currentpageindex) ProductID from Products)
return @@rowcount
当我在sql中执行(因为gridview pageindex是从0开始计数的)USE [Northwind]
GODECLARE @return_value int,
@rowcount intEXEC @return_value = [dbo].[GetProductsByPagenum]
@pagesize = 10,
@currentpageindex = 0,
@rowcount = @rowcount OUTPUTSELECT @rowcount as N'@rowcount'SELECT 'Return Value' = @return_valueGO查询出来的结果是10条, ProductID是从1到10
但是当我用sqlcommand调用这个存储过程的时候 查出来的行数为5 ProductID是从1到5 DataSet ds = new DataSet();
string connectionString = @"Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True";
SqlConnection cn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("GetProductsByPagenum", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@pagesize", SqlDbType.Int, this.GridView1.PageSize);
param[1] = new SqlParameter("@currentpageindex", SqlDbType.Int, this.GridView1.PageIndex);
param[2] = new SqlParameter("@rowcount", SqlDbType.Int);
param[2].Direction = ParameterDirection.Output;
cmd.Parameters.AddRange(param); SqlDataAdapter adapt = new SqlDataAdapter(cmd);
adapt.Fill(ds);
count = Convert.ToInt32(cmd.Parameters[2].Value);
return ds.Tables[0];我找了下,没发现原因在哪......
@currentpageindex 就是gridview的current page indexUSE northwindALTER PROCEDURE [dbo].[GetProductsByPagenum]
(
@pagesize int = 5,
@currentpageindex int=1,
@rowcount int output
)
AS
/* SET NOCOUNT ON */
select @rowcount=count(*) from Products select top (@pagesize) *
from Products
where ProductID not in (select top (@pagesize*@currentpageindex) ProductID from Products)
return @@rowcount
当我在sql中执行(因为gridview pageindex是从0开始计数的)USE [Northwind]
GODECLARE @return_value int,
@rowcount intEXEC @return_value = [dbo].[GetProductsByPagenum]
@pagesize = 10,
@currentpageindex = 0,
@rowcount = @rowcount OUTPUTSELECT @rowcount as N'@rowcount'SELECT 'Return Value' = @return_valueGO查询出来的结果是10条, ProductID是从1到10
但是当我用sqlcommand调用这个存储过程的时候 查出来的行数为5 ProductID是从1到5 DataSet ds = new DataSet();
string connectionString = @"Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True";
SqlConnection cn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("GetProductsByPagenum", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@pagesize", SqlDbType.Int, this.GridView1.PageSize);
param[1] = new SqlParameter("@currentpageindex", SqlDbType.Int, this.GridView1.PageIndex);
param[2] = new SqlParameter("@rowcount", SqlDbType.Int);
param[2].Direction = ParameterDirection.Output;
cmd.Parameters.AddRange(param); SqlDataAdapter adapt = new SqlDataAdapter(cmd);
adapt.Fill(ds);
count = Convert.ToInt32(cmd.Parameters[2].Value);
return ds.Tables[0];我找了下,没发现原因在哪......
解决方案 »
- 一个复选框问题
- asp.net 请问天台js函数能不能直接调后台的按钮事件,做到和点击按钮是一个效果?(这个js函数和画面上的按钮一点关系都没有)
- 请编程遍历页面上所有TextBox控件并给它赋值为string.Empty?
- 在同时使用Cookie和Session时出现的问题
- vs.net2003不能新建项目,并提示当前web服务器运行的是asp.net 1.0,需要进行配置,请教大家有谁遇到过吗!
- 这个问题应该有些BT吧.
- frame的小问题,望有经验者指点
- 什么是:此页的视图状态无效,可能已损坏 是什么造成的???
- 大家帮个忙~~
- 谁有把汉字转化成拼音的函数,要asp.net的,最好是C#的
- 用户控件里用验证控件的问题
- 怎么取返回记录列表中最后一个记录数?
GridView1.PageSize=10
看一下它是多少!
this.GridView1.PageInde 是0
哦对阿..........我怎么忘了这样东西..........不过.........我装的是sql express
express 有事件察看器吗