string csac = ConfigurationSettings.AppSettings["acConnectionString"];
   
 //创建AdoHelper
 AdoHelper helperac = AdoHelper.CreateHelper("oleDBDA");
   PagedDataSource pds = new PagedDataSource();
   pds.DataSource =helperac.ExecuteReader(csac,System.Data.CommandType.Text, "select * from roles");  //出错行
GridView2.DataSource = pds;
GridView2.DataBind();
错误是“CS0266: 无法将类型“System.Data.IDataReader”隐式转换为“System.Collections.IEnumerable”。存在一个显式转换(是否缺少强制转换?)”
应该怎么弄呢。
pds.DataSource = helperac.ExecuteDataset(csac, System.Data.CommandType.Text, "select * from roles").Tables[0].DefaultView;
这个方法的可以。datareader怎么不行呢。该怎么做呢。

解决方案 »

  1.   

    分页要求的数据源必须实现IEnumerable接口,所以你要考虑使用返回为DataSet(实现了IEnumerable接口)的方法,而不是DataReader
      

  2.   

    如果你是 直接传 的 已经分好页的 数据
    那么直接给
    string csac = ConfigurationSettings.AppSettings["acConnectionString"];
       
     //创建AdoHelper
     AdoHelper helperac = AdoHelper.CreateHelper("oleDBDA");
       
    GridView2.DataSource = helperac.ExecuteReader(csac,System.Data.CommandType.Text, "select * from roles");  //这样是可以的
    GridView2.DataBind();如果你要使用GridView自己的分页功能 那么必须是使用DataSet这样的实现了IEnumerable接口的数据类型
      

  3.   

    原来是这样啊。用PagedDataSource 分页的数据源必须是实现IEnumerable接口吗?
      

  4.   

    当然 建议 楼主 使用 存储过程来分页可参见.http://blog.csdn.net/hertcloud/category/281167.aspx
      

  5.   

    to hertcloud(·£孙子兵法£·) 我是在测试access数据库。
    GridView2.DataSource = helperac.ExecuteReader(csac,System.Data.CommandType.Text, "select * from roles");  //这样是可以的
    GridView2.DataBind();
    这样我启动GridView2自动分页,出现“System.NotSupportedException: 数据源不支持服务器端的数据分页。“ 这个错误。