How to copy a specific amount of rows from a datatable to another

Hi, I have an initial DataTable (dt_CaseWareFiles) in wich I have to extract “N” number of rows (stored in variable int_NumberSamples) and add them to a new DataTable (dt_TestingSamples) and then those rows added to the new DT, I need to remove/delete them from the initial DT.
Thanks in advance for your help.

Hi!

If you wants to extract the rows just do like this!

rows count(dt.Rows.Count.ToString)

Read the column by using for each row in datatable.

Take one build data table and mention the rows which is present in the input file.

if you wants to add those rows to new data table just use add data row inside the properties in array of rows mention the columns like this {Column1,Column2,Column3} mention DT as your output of build dt

Sample File:

SplitCells.zip (16.3 KB)

Regards,
NaNi

Hi @Allison_Cruz

You can try with filter datatable activity!

Read range the Initial dt

Then Use filter datatable activity to perform the filter based on the columns

first use option to keep the row values as datatable and store it a newDt1

Second use Option to remove the rows values and store it a newDt2 in Filter datatable activity

Then use append range to append the newDt1 in newDatatable

Regards

1 Like

What if the input data table number of columns can be a different number each time? :confused:
Because the input DataTable is the result of a Read Range Excel activity, and that excel file is differente everytime I run the robot

Hi @Allison_Cruz

Use the Expression like below

To Take n number of rows

InitialDt.AsEnumerable.Take(rowsYouneed to fetch as integer).Copytodatatable

To Skip n number of rows

IntialDt.AsEnumerable.Skip(Rows you need toSkip as Interger).CopyTodatatable

Append the TakeDt in Newdatatable

write range the SkipDt

Regards

4 Likes

Thank you very much, I already tested and it works exactly as I needed!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.