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 ?
It sounds like this post contains the solution for the problem you’re tackling.
Please let me know if this was helpful or not.
I’m trying to get the robot to run through all the rows in the excel and enter the details in a website 10 names by 10 names. I can do a variable.Rows(0)(“Name”).ToString up to a certain number but the list of names I receive somewhere can be unknown. Do I do a loop if so, how to get the robot to read the 11th row after completing the first batch of 10 rows for example?
Many thanks for the help in advising this.
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.
Sounds like a plan.
I’ll be sure to reach out if I find a better solution in the future!
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:
let me introduce a general approach that can be also adopted to more case specific details.
DataTable with 8 Rows
Following Building Blocks are used
Calculation of the numbers of segments:
with the Ceiling method the fractions are uprounded to the next Integer
with the Skip() and Take() Method the Rows for a segment can be retrieved.
the different segments are bult by following
and do fetch the different segment rows by: …
in the combination with copytodatatable split results are datatables: