protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {
            SqlConnection conn = DB.getConnection();
            conn.Open();
            SqlCommand Count = new SqlCommand();
            Count.Connection = conn;
            Count.CommandText = "select count(*) from T_SoftDown1";
            AspNetPager1.RecordCount = (int)Count.ExecuteScalar();
            //Response.Write(AspNetPager1.RecordCount);
            conn.Close();
            BindData();
        }    }    public void BindData()
    {
        SqlConnection conn = DB.getConnection();
        string sql = "select * from T_SoftDown1 order by E_id desc";//这句在大型数据中应该用:select top查询语句
        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
        DataSet ds = new DataSet();
        da.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "temptbl");
        DataTable dt = ds.Tables["temptbl"];
        SoftDown.DataSource=dt;
        SoftDown.DataBind();
    }上面调用下面的方法,可是上下都有sql语句,各自代表什么意思呢?

解决方案 »

  1.   

    "select count(*)只是得到总记录数
    select * from T_SoftDown1 order by E_id desc
    才是得到具体的内容
      

  2.   

    上面count(*)是统计记录总数  下面查询是查询所有数据赋值给数据源
      

  3.   

    public void BindData(int userId)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["db_health"].ConnectionString;
            SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
            string sql = "select * from health_user_followup_content where user_id=" + userId + "";
            SqlDataAdapter da = new SqlDataAdapter(sql,conn);
            DataSet ds = new DataSet();
            da.Fill(ds.AspNetPager1.PageSize*(AspNetPager1.CurrentPageIndex-1),AspNetPager1.PageSize,"FollowContent");
            DataTable dt = ds.Tables["FollowContent"];
            rpUserList.DataSource = dt;
            rpUserList.DataBind();
        }
    da.Fill(ds.AspNetPager1.PageSize*(AspNetPager1.CurrentPageIndex-1),AspNetPager1.PageSize,"FollowContent");
    这句话的ds.AspNetPager1报出下面的错误
        //“System.Data.DataSet”不包含“AspNetPager1”的定义,并且找不到可接受类型为“System.Data.DataSet”的第一个参数的扩展方法“AspNetPager1”(是否缺少 using 指令或程序集引用?