// PageCount取不到值,为0 string strconn = System.Configuration.ConfigurationSettings.AppSettings["connStr"].ToString();
SqlConnection conn = new SqlConnection(strconn);
int PageIndex = System.Convert.ToInt32( Request.QueryString["PageIndex"]);
int PageSize = 10;
int PageCount;
string ViewName="Record";
string Field = "*";
SqlCommand comm = new SqlCommand("Pagination",conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@PageIndex",SqlDbType.Int);
comm.Parameters["@PageIndex"].Value=PageIndex; comm.Parameters.Add("@PageSize",SqlDbType.Int);
comm.Parameters["@PageSize"].Value=PageSize; comm.Parameters.Add("@RecordCount",SqlDbType.Int);
comm.Parameters["@RecordCount"].Direction=ParameterDirection.Output; comm.Parameters.Add("@PageCount", SqlDbType.Int);
comm.Parameters["@PageCount"].Direction = ParameterDirection.Output; comm.Parameters.Add("@ViewName", SqlDbType.VarChar, 50);
comm.Parameters["@ViewName"].Value = ViewName; comm.Parameters.Add("@Field", SqlDbType.VarChar, 200);
comm.Parameters["@Field"].Value = Field; conn.Open();
SqlDataReader dr = comm.ExecuteReader();
PageCount = System.Convert.ToInt32(comm.Parameters["@PageCount"].Value);//PageCount取不到值,为0
//string strPageCount = comm.Parameters["@RecordCount"].Value.ToString(); GetPageInfo(PageIndex, PageCount); DataList1.DataSource = dr;
DataList1.DataBind();
conn.Close();
conn.Dispose();
SqlConnection conn = new SqlConnection(strconn);
int PageIndex = System.Convert.ToInt32( Request.QueryString["PageIndex"]);
int PageSize = 10;
int PageCount;
string ViewName="Record";
string Field = "*";
SqlCommand comm = new SqlCommand("Pagination",conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@PageIndex",SqlDbType.Int);
comm.Parameters["@PageIndex"].Value=PageIndex; comm.Parameters.Add("@PageSize",SqlDbType.Int);
comm.Parameters["@PageSize"].Value=PageSize; comm.Parameters.Add("@RecordCount",SqlDbType.Int);
comm.Parameters["@RecordCount"].Direction=ParameterDirection.Output; comm.Parameters.Add("@PageCount", SqlDbType.Int);
comm.Parameters["@PageCount"].Direction = ParameterDirection.Output; comm.Parameters.Add("@ViewName", SqlDbType.VarChar, 50);
comm.Parameters["@ViewName"].Value = ViewName; comm.Parameters.Add("@Field", SqlDbType.VarChar, 200);
comm.Parameters["@Field"].Value = Field; conn.Open();
SqlDataReader dr = comm.ExecuteReader();
PageCount = System.Convert.ToInt32(comm.Parameters["@PageCount"].Value);//PageCount取不到值,为0
//string strPageCount = comm.Parameters["@RecordCount"].Value.ToString(); GetPageInfo(PageIndex, PageCount); DataList1.DataSource = dr;
DataList1.DataBind();
conn.Close();
conn.Dispose();
解决方案 »
- aspx中的一个问题</script> 匹配的问题
- 急,在vs2005(C#)web开发中怎么用FileUpload控件将上传的文件直接写进Oracle数据库中BLOB类型的字段中??
- MemberShip是使用什么机制进行验证的??
- help Repeater1_ItemDataBound是怎么用???
- 有个问题困扰了我很久了
- viewstate到底什么时候该为true,什么时候该为false啊?
- 为什么我的treeview不能用,显示很怪-------在线等。
- 关于DropDownList下拉菜单的取值问题
- 调试时候出错提示的语言问题
- 给点意见就有分拿~~快来帮帮忙呀,谢谢各位先。。。
- 关于打开文件类型问题
- asp.net2.0柱型图表的设置问题
这句改成:
comm.ExecuteNoQuery();
comm.Parameters.Add("RecordCount",SqlDbType.Int);
comm.Parameters["RecordCount"].Direction=ParameterDirection.Output;PageCount = System.Convert.ToInt32(comm.Parameters["PageCount"].Value);//
drop proc Pagination
go
CREATE proc Pagination
@PageIndex int,--索引,1为首页
@PageSize int,--页面尺寸
@RecordCount int output,--总记录数
@PageCount int output, --总页数
@ViewName varchar(100),--视图名
@Field varchar(500)
as
--总记录数
declare @strCount nvarchar(200) set @strCount ='select @RecordCount=count(*) from '+@ViewName
exec sp_executesql @strCount,N'@RecordCount int out',@RecordCount out
--print str(@RecordCount)
--总页数
set @PageCount=(@RecordCount/@PageSize)+1 --TopCount
declare @TopCount int
set @TopCount=@RecordCount-(@PageIndex-1)*@PageSize
--SqlStr
declare @SqlStr varchar(2000)
if @Field=''
begin ------1
set @Field=' * '
end ------1
if (@PageIndex=1 or @PageIndex=null)
begin ------1
-- print 'OK'
set @SqlStr ='select Top '+str(@PageSize)+' '+@Field+' from '+@ViewName+' order by id desc'
end ------1
else
begin -----2
if (@PageCount=@PageIndex)
begin ---3
set @SqlStr ='select '+@Field+' from (select Top '+str(@TopCount)+' * from '+@ViewName+' order by id asc)ByName order by id asc'
end ----3
else
begin ---4
set @SqlStr ='select Top '+str(@PageSize)+' '+@Field+' from (select Top '+str(@TopCount)+' '+@Field+' from '+@ViewName+' order by id asc)ByName order by id desc'
end ----4
end -------2
--print @SqlStr
--print @PageCount
exec(@SqlStr)--Pagination 1,3,'','','Record',''GO
dr.SelectCommand = comm;
comm.ExecuteNonQuery();
按你的程序只需要执行那个存储过程就可以 了而不需要得到数据集合什么的,返回值可以利用output的参数传递出来
select * from a)而你此时的返回值实际是通过一个output参数来传递的,整个存储过程执行后的返回值其实是没有的。
先取总的记录数、、、