日期:2014-05-19  浏览次数:20403 次

CS0266:错误帮忙看看。多谢
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怎么不行呢。该怎么做呢。




------解决方案--------------------
分页要求的数据源必须实现IEnumerable接口,所以你要考虑使用返回为DataSet(实现了IEnumerable接口)的方法,而不是DataReader
------解决方案--------------------
如果你是 直接传 的 已经分好页的 数据
那么直接给


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接口的数据类型
------解决方案--------------------