@sherpa24, we have LINQ to solve your requirement. But as you are in a need to learn how datatable works, am sharing this from what I have understood.
Datatable is like a matrix where we can access the row and column with same mathematical logic.
dt.Rows(0)(0) - First Row First Column
dt.Rows(0)(1) - First Row Second Column
dt.Rows(1)(0) - Second Row First Column
dt.Rows(1)(1) - Second Row Second Column
Let’s take this above example,
- Run For Each Row in D1
- Inside body of for each row place a If Condition and check this condition,
row("Column1").ToString.Equals(D2.Rows(D1.Rows.Indexof(row))("Column1"))
Here we are taking the D1 table’s row reference (Index) to get the D2 table rows value - in Then part of if condition place a Message Box and paste this condition,
D2.Rows(D1.Rows.Indexof(row))("Column2").tostring
This will take value from D2 column2 when column1 from D1 and D2 matches.
NOTE: You can go through our forum posts regarding excel automation and search for solved xamls where you will get a detailed and clear understanding.
Regards,
Dominic