How to split data table into multiple tables with adding 1 minute delay

后端 未结 1 1134
情书的邮戳
情书的邮戳 2020-12-04 03:23

I know there are a lot of questions and solutions related to it. But I am not getting them. I have a data table of records 8000 and it will increase in the futu

相关标签:
1条回答
  • 2020-12-04 04:08

    I hope this is what you want to achieve:

    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Threading;
    

    ...

        public void Test()
        {
            DataTable bigDataTable = GetBigDataTable();
            var splitedTables = new List<DataTable>();
            var smallTable = new DataTable();
            int page = 1;
            int pageSize = 1000;
            List<DataRow> results;
            while (true)
            {
                results = bigDataTable.AsEnumerable().Skip(pageSize * page++).Take(pageSize).ToList();
    
                if (!results.Any())
                    break;
    
                smallTable = results.CopyToDataTable();
                splitedTables.Add(smallTable);
    
                Thread.Sleep(1000 * 60 * 1);
            } while (results.Any());
        }
    

    For this to work you need to add reference to System.Data.DataSetExtensions.

    This is also similar question in SO.

    0 讨论(0)
提交回复
热议问题