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?
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)
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”.