Split datatable into batches

Hi All,

I have a master datatable which will have roughly 150-200 rows.

Now I have to split this datatable into batches of 30 and this has to be dynamic because I will not know how many rows my master datatable can have, so i can’t put static values.

As for now, I have split 2 batches of 30 each as below:

batch1DtTble = dtTble.AsEnumerable().Take(30).CopyToDataTable()

batch2DtTble = DtTble.AsEnumerable().Skip(30).Take(30).CopyToDataTable()

I can still continue with the same approach and get all the batches but I’m looking for some dynamic approach to split batches in run time or something more flexible approach working with total rows in my master datatable to be split.

Any suggestions, please ?


Good evenong @malhotraneha162000,

It sounds like this post contains the solution for the problem you’re tackling.

Please let me know if this was helpful or not.

Hi @chenderson,

Thanks for your quick response!

I reckon the solution provided will work. I will implement the solution and will get back If I get struck somewhere.


1 Like

Sounds like a plan.

I’ll be sure to reach out if I find a better solution in the future!

1 Like

I am looking for the same solution…do we have a dynamic approach…wherein the n number records would be splitted into batches of 30 and resume the next batch till end?

Hey , iam looking for that solution if you cracked it pls help me with that

can be done with skip take:

in the combination with copytodatatable split results are datatables: