split datatable to multi datatable c#

0 thích 0 không thích
1 lượt xem
đã hỏi 24 Tháng 3, 2022 trong Lập trình C# bởi nguyenthao (9,000 điểm)
 public static IEnumerable<IEnumerable<T>> ToChunks<T>(this IEnumerable<T> enumerable,
                                                      int chunkSize)
        {
            int itemsReturned = 0;
            var list = enumerable.ToList(); // Prevent multiple execution of IEnumerable.
            int count = list.Count;
            while (itemsReturned < count)
            {
                int currentChunkSize = Math.Min(chunkSize, count - itemsReturned);
                yield return list.GetRange(itemsReturned, currentChunkSize);
                itemsReturned += currentChunkSize;
            }
        }

using :

 var listTable = dt_source.AsEnumerable().ToChunks(8)
                          .Select(rows => rows.CopyToDataTable());

    

1 câu trả lời

0 thích 0 không thích
đã trả lời 24 Tháng 3, 2022 bởi nguyenthao (9,000 điểm)
very helpul ... thanks
...