Write row of existing DataTable to new DataTable in For Each Row

Hello,

I am currently trying to compare two DataTables, and add a row to a new DataTable if the row of DataTable A (inputdata) column 1 contains the same value as DataTable B (ReadOutput) column 1, and DataTable B (ReadOutput) contains “Posting” in column 5. See the below screenshot:

I have the comparison code, but I cannot work out how to add the DataRow of DataTable A to a new DataTable. row inside of the For Each Row is part of a DataTable so I cannot write it to a new DataTable, andinputdata.Rows(CompareCount) is classed as an object. Does anybody have a method of adding a DataTable row to a new DataTable?

Thanks in advance

Instead of using the DataRow object as input for the new datatable, you can construct an array of the column values on the fly and pass it as input for the new datatable.
Use the ArrayRow object to do this. (Seen in Properties tab in your screenshot)

Example:
{“column 1”, “column 2”, column3} …

1 Like

Hello,
I had a similar job, but a for each needed too much time so I solved it with “join data tables” and then “filter data table”:
I joined my datatables a and b with join type “full” to a new DT and did a filter on the new DT. Maybe this would work for you as well?

For Your job You just define, that column 1 of DT A must be the same as column 1 of DT B. After that you filter the new DT an keep only that rows, where Column 5 contains “Posting”.

Hope it works!
Moritz

2 Likes

Hey @RPAForEveryone,

Thanks for the reply. I set the arrayRow value to a list of variables and it worked great.

Thank you for your time @RPAForEveryone @mm1904

1 Like

Glad to be of assistance!

Happy automation!
Cheers,
Ash @ RPAForEveryone.com

1 Like

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