Cross referencing two data tables

Hi,

I have two data tables which contain items and values. I want to essentially check 'if data table A row(0) contains something which exists in any row(0) of data table B to remove the row of DT A.

I thought that the following would work:

However, I am being met with the error once it removes the first matching item: For Each Row: Collection was modified; enumeration operation might not execute.

Could anyone please explain why this might be happening and how I fix it?

Thank you!

Hi.
You cant remove rows in for each row loop.
But you can use simple for each loop with row index as argument.
Something like:

For each index in Enumerable.Range(0,DT.RowCount)

With analogical logic inside of the loop

1 Like

Thank you for your suggestion, I actually fixed it now by writing ‘not’ in the if statement and instead writing it to a new data table rather than removing it.

Thank you though!

Hello @dr1992
When you try to delete the row of the current data table in looping, such an error occurs.

Try to clone the factory data table and use one to loop and another one to remove data.

Otherwise use the filer data table option.

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