//  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();

解决方案 »

  1.   

    SqlDataReader dr = comm.ExecuteReader();
    这句改成:
    comm.ExecuteNoQuery();
      

  2.   

    这样试试
    comm.Parameters.Add("RecordCount",SqlDbType.Int);
    comm.Parameters["RecordCount"].Direction=ParameterDirection.Output;PageCount = System.Convert.ToInt32(comm.Parameters["PageCount"].Value);//
      

  3.   

    --还是不行,我的存储过程如下,在查询分析器能打印出@PageCountr的值
    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
      

  4.   

    改成这样就可以了,大家能说说原因吗?   SqlDataAdapter dr = new SqlDataAdapter();
       dr.SelectCommand = comm;
      comm.ExecuteNonQuery();
      

  5.   

    按你的程序来看,ExecuteReader()是用来得到一个只读的数据集合,个人猜测,你的返回值可能在datareader里面!而不是那个参数里面!!!
    按你的程序只需要执行那个存储过程就可以 了而不需要得到数据集合什么的,返回值可以利用output的参数传递出来
      

  6.   

    个人猜测,你的返回值可能在datareader里面---这个只是猜测,没试验过不知道
      

  7.   

    一般来说ExecuteReader()是需要存储过程返回的是一个数据集(比如存储过程函数主体是
    select * from a)而你此时的返回值实际是通过一个output参数来传递的,整个存储过程执行后的返回值其实是没有的。
      

  8.   

    PageCount取不到值,为0 
    先取总的记录数、、、