Create an Array of ALL DataRows of a DataTable

Hey,
so I know I can use “Select” to create an Array of specific DataRows of a DataTable.
But I want to create an Array of ALL the DataRows in a DataTable.

I’m struggeling to use Select to get an Array with all the Rows.

How would I do this?

Thanks in advance!

1 Like

Buddy @Olaf1

Welcome to uipath community buddy

1…you can use for each row loop activity buddy
the outcome of this loop will be a variable row, which will be type datarow
so you can get all the datarow of a table by just iterating with for each row loop
or
2. you can use assign activity with a variable of type array of datarowcollection and mention like this buddy

out_datarow_array = out_dt.Rows
or
3. you can get by the method you used buddy
out_datarow_array = out_dt.Select()
where out_datarow_array is of type array of datarow

Kindly try this and let know buddy

Cheers @Olaf1

1 Like

@Olaf1

use DatatableVriable .Select()

You will get all the rows as an array

2 Likes

This is the following codes for Create an Array of ALL DataRows of a DataTable from given Oracle DBA table, My SQL Table and many more.

DataTable dt = new DataTable();
foreach (DataRow dr in drResults)
{
dt.ImportRow(dr);
}

did that work buddy @Olaf1

Yeah, thanks for your solutions, but unfortunately now I have a different problem…

So here is what I was trying to do:

I have two DataTables. I want to remove all the DataRows in the first DataTable that are duplicates in the second DataTable.
So I thought I could create an array of all the Rows in the second DataTable and remove them from the first DataTable… but that gave me an error. Guess I can’t remove the Items in the Array from the second DataBase from the first one.

Any suggestions how I would to this?

Hi @Olaf1,

If I well understand your issue, your goal is to merge two DataTables without having duplicated lines right ?

If so, you’ll find attached an example of what I already made. You need to specify the datatables “Primary Keys” to avoid duplication.

XAML : Main.xaml (12.8 KB)

Hope it helps.

Regards,

@Masire

Here is just another solution using LINQ that would look for each row in second table and not include it in first table:
dt1.AsEnumerable.Where(Function(r1) dt2.AsEnumerable.Where(Function(r2) r2(0).ToString.Trim = r1(0).ToString.Trim ).ToArray.Count = 0 ).CopyToDataTable

0 index can be replace with “columnname” if desired, and for multiple criteria to match the row up, you can use AND, like r2(0).ToString.Trim = r1(0).ToString.Trim And r2(1).ToString.Trim = r1(1).ToString.Trim

Alternatively, you can use .ItemArray to compare the rows, assuming the rows will have identical values.
dt1.AsEnumerable.Where(Function(r1) dt2.AsEnumerable.Where(Function(r2) String.Join(",",r2.ItemArray) = String.Join(",",r1.ItemArray) ).ToArray.Count = 0 ).CopyToDataTable

3 Likes