I have a large DataTable, and I want to split it into multiple smaller DataTables—each containing a fixed number of rows (for example, 500 rows per chunk).
Is there a faster or more efficient method to achieve this in UiPath without relying on standard For Each loops, especially when working with very large datasets?
Example
Input DataTable: 10,000 rows Desired Output:
DataTable_1 → Rows 1–500
DataTable_2 → Rows 501–1000
DataTable_3 → Rows 1001–1500
…and so on
I’m looking for an optimized or built-in approach (LINQ, .NET methods, Invoke Code, or any other best practice) that can perform this “row chunking” efficiently.
Any suggestions or sample code would be really helpful.
you can use Datatablevariable.AsEnumerable.Chunk(500) this given as input for loop..will send 500 rows each time as a set and isnide loop for each iteration you would get 500 or less items ..for last iteration if 500 are not there then it would send how many ever are left
You can try through LINQ, change code accordingly:
chunks = dt.AsEnumerable().
Select(Function(r,i) New With {.Row=r, .Index=i}).
GroupBy(Function(x) x.Index \ 500).
Select(Function(g) g.Select(Function(x) x.Row).CopyToDataTable()).
ToList()