Maybe you could try with the below steps :
-
Assuming you have read the data from the two sheets and have got the datatables, let’s say
DT1
andDT2
. -
Now, We will fetch the ID and year values from
DT1
and concatenate it and get all the concatenated values as a list/array.
IdYearArray = DT1.AsEnumerable.Select(Function(x)x("ID").ToString.Trim+x("Year").ToString.Trim).Distinct.ToArray
Here, IdYearArray
is of the type Array of String.
- Next, we filter the
DT2
datatable with the fetchedIdYear
values fromDT1
like below :
DT3 = DT2.AsEnumerable.Where(Function(x)IdYearArray.Contains(x("ID").ToString.Trim+x("Year").ToString.Trim)).CopyToDatatable
Here, DT3
is the resultant datatable (needs to be created).
Also, Check the below on handling Exceptions on direct CopyToDatatable
.
Let us know if you are able to follow the approach mentioned.