Optimizacion de for each row

Hi everyone, I need help with the following, I have two data tables and I am using two for each row (one within the other) to find the match between both data tables.
What happens is that both datatables will grow as the days go by so the search for matches will be increasingly delayed.
What other method can I use to optimize this search?
I would appreciate a lot

You can use Linq query to compare or fins match between two datatables and below the sample linq query,
DT1.AsEnumerable().Where(Function(row) DT2.AsEnumerable().Where(Function(row1) row1(“ColumnName1”).ToString.Equals(row(“ColumnName1”).ToString) and row1(“ColumnName2”).ToString.Equals(row(“ColumnName2”).ToString)).Any).CopyToDataTable()
Hope this may help you :slight_smile:

1 Like

@Manish540 Thank you very much, with this I managed to solve, but I have one last question, how do I do the opposite, obtain a datatable with the rows that do not match?
I tried to do it by adding a not to the condition, but it didn’t work for me
DT1.AsEnumerable (). Where (Function (row) out_dtFormulario.AsEnumerable (). Where (Function (row1) not row1 (“Enter the electronic invoice number (20 digits)”). ToString.Equals (row (“Invoice”) ) .ToString)). Any) .CopyToDataTable ()

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