Filter two datatable based on common column and get only values matched in first datatable using linq

Hi everyone,
My requirement is i have two excel
1.both has common columns “Emp Id”
2.i need to compare dt1 with dt2 with “emp id” and filter out only matched “emp Id” rows from dt1

Thanks in advance

Hi @kavya.s16 ,

For a simple check, could you try using the Join Datatables Activity with Join Type as Inner Join ?

We could then keep only the columns of the DT1 in the resultant datatable using the DefaultView.ToTable() method.

Let us know if it works out for your case.

@supermanPunch Hi , i tried inner join but it includes both dt1 and dt2 whereas i need only dt1 matches rows , how to use that defaultview.toTable() method?

@kavya.s16 ,

Use the Expression like below in an Assign Statement:

OutputDT = OutputDT.DefaultView.ToTable(false,DT1.Columns.Cast(Of DataColumn).Select(Function(x)x.ColumnName.ToString).ToArray)

Here, OutputDT is result from Join Datatables Activity, DT1 is the datatable whose columns you would want to preserve.

Let us know if it doesn’t work as expected.