IDATAREADER 与 DATATABLE 读取数据

  
  
  
  
  1. IDataReader reader = command.ExecuteReader(); 
  2. int i = 0; 
  3.             while (reader.Read() && i < sliderSize) 
  4.             { 
  5.                 int id = Convert.ToInt32(reader["ID"]); 
  6.                 string pic = reader["PIC"].ToString(); 
  7.                 string title = reader["TITLE"].ToString(); 
  8.                 _rvl.Add(new ADsInfo { ID = id, PIC = pic, TITLE = title }); 
  9.                 i++; 
  10.             } 
  
  
  
  
  1. DataTable dt = db.CenterSlidePlayerAd(); 
  2. DataRow[] rootRows = dt.Select(); 
  3. foreach (DataRow dr in rootRows) 
  4.             { 
  5.                 int id = Convert.ToInt32(dr["ID"]); 
  6.                 string pic = dr["PIC"].ToString(); 
  7.                 string title = dr["TITLE"].ToString(); 
  8.                 _rvl.Add(new ADsInfo { ID = id, PIC = pic, TITLE = title }); 
  9.                 if ((++i) > (sliderSize - 1))//取5条广告,sliderSize=5 
  10.                     break
  11.             }      

 

你可能感兴趣的:(reader,Datatable,休闲,DataRow,IDataReader)