Click here to Skip to main content
15,906,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)
Posted

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;
           }
 
Share this answer
 
Comments
Keerthi Kumar(Andar) 24-Jan-14 1:39am    
thanks a lot RhishikeshLathe..
RhishikeshLathe 24-Jan-14 1:44am    
Thank you for accepting solution.
Happy weekEnd.
try this


C#
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
       }
 
Share this answer
 
Comments
Keerthi Kumar(Andar) 24-Jan-14 1:32am    
thanks a lot karthik
Karthik_Mahalingam 24-Jan-14 3:25am    
Welcome Keerthi Kumar(Andar) :)
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900