Iterating through data tables and comparing

Hello everyone!

I have been browsing through the forum and have found very similar questions but none that quite answer what I need to do.

The goal is to compare two data tables at every cell, and write “match” or “mismatch” to a third data table at each cell.

My logic so far in pseudocode is this:

But I end up with a blank dt3.

Any thoughts or suggestions?

Thank you so much in advance!

You dont need nested loops. You just need one loop with index i running from 0 to rows count. Then compare row1.item(i) with row2.item(i) and set row3.item(i).

1 Like

Thank you for your response! That makes sense as I only need to iterate through each data table once. I have been attempting to implement that solution.

However, I am getting an error. I’m attempting to write to a data table dt3 that is initially empty, for example: dt3(i)(j) = “match”
When I attempt to do this, I get the error “Assign: Cannot create an L-value from the given expression with property ‘set_item’ because the target object is null.” Then I tried doing dt3.Rows(i)(j) and got another error, data table contains no rows. So i put an empty row in the data table before every new row i write to but am still getting errors.

Any ideas how to write to a particular cell of a data table that does not have any data yet?

@Jason_Skipper - Please check this page, this may help you …

1 Like

Thanks guys! I ended up finding a solution, the third data table is not necessary, you can just write over the data in the second data table. my modified algorithm is as follows:
i = 0
ForEach rowD in dt1
j = 0
if( dt1(i)(j).ToString = dt2(i)(j).ToString )
dt2(i)(j) = “match”
dt2(i)(j) = “mismatch”
j = j + 1
while(j < dt1.Columns.Count)

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