如何将数据表拆分为多个数据表 [英] How to split the datatable to multiple datatable

查看:87
本文介绍了如何将数据表拆分为多个数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,

你有一个数据表它包含5000条记录。

其中我希望每次迭代时向网络服务发送500条记录。

现在我的问题是

如何将包含5000条记录的数据表拆分为10条作为500条记录?



任何人都可以帮我解决这个问题吗?



提前谢谢

(Keerthi Kumar)

Hi experts,
Hi have one data table it contains 5000 records.
out of these i want to send 500 record to a web service each time in a iteration.
Now my quetion is
how to split the data table which contains 5000 records to 10 parts as 500 records?

Can any one please help me to solve this issue?

thanks in advance
(Keerthi Kumar)

推荐答案

请参阅以下代码,



Refer following code,

DataTable myDatatable = new DataTable();//Original datatable
           int iCount = 2;//count for each chunk
           int iIndex = 0;
           while ( iIndex < myDatatable.Rows.Count)
           {
               DataTable dtChunk = myDatatable.AsEnumerable().Skip(iIndex).Take(iCount).CopyToDataTable();
               iIndex = iIndex + iCount;
           }


试试这个





try this


int total = dt.Rows.Count;
       int countneeded = 5000;
       int split = total / countneeded;

       for (int i = 0; i < split; i++)
       {
           var Dt5000=  dt.Rows.OfType<DataRow>().Skip(i * countneeded).Take(countneeded).ToArray();
            // this Dt5000 has 5000 rows
       }


您可以通过循环遍历数据表并选择所需的数据行,也可以从DataTable中选择以获取数据行。
You can have a loop to go through your datatable and select no of data rows you need or you can select from DataTable to get data rows.


这篇关于如何将数据表拆分为多个数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆