Sometimes we might be asked to process only the top N records out of the total available records in the DataTable.
Let us see how to implement it!!!
 new_DataTable=old_DataTable.AsEnumerable().Take(N).CopyToDataTable()
Note:
Replace old_DataTable with your DataTable
N = 1,2,3….
Example
Implementation using UiPath :
Let us implement a workflow which takes a sample DataTable and displays the top N records of it, according to our supplied input.
Step 1:
Drag “Build Data Table” activity into the designer panel and insert some sample data into it.
Step 2:
Drag “Assign” activity into the designer panel and populate it with the below code.
dt_Sample.AsEnumerable().Take(3).CopyToDataTable()
Step 3:
Drag “Output Data Table” activity into the designer panel to convert Datatable to String type.
Step 4:
Drag “Message Box” activity into the designer panel to display the modified data table.
Step 5:
Finally, let’s run the project.
Click here to download the Source Code…
Hope it has helped you…