分割DataTable

  /// <summary>
        
/// 分割数据集
        
/// </summary>
        
/// <param name="dtData">数据集</param>
        
/// <param name="Number">分多少个</param>
        
/// <returns></returns>
        private IList<DataTable> ListData(DataTable dtData, int Number)
        {
      
            List<DataTable> dtList = new List<DataTable>();
            double meiye=Math.Ceiling(dtData.Rows.Count / (double)Number);
            for (int i = 0; i < Math.Ceiling(dtData.Rows.Count / (double)meiye); i++)
            {
                DataTable subdt = new DataTable();
                subdt = dtData.Clone();
                dtData.AsEnumerable().Skip(Convert.ToInt32(meiye * i)).Take(Convert.ToInt32(meiye)).ToList().ForEach(name => subdt.ImportRow(name));
                dtList.Add(subdt);
            }
            return dtList;
        }
posted @ 2012-05-30 13:41  王大湿  阅读(388)  评论(0编辑  收藏  举报