Kindly help to compare 2 datatables with 2 maatching conditions and 1 unmatching condition to get records

Compare 2 datable with 3 Conditions

  1. Serial Number should Match in both Datatables
  2. Phone Match should match in both Datatables
  3. Employee Number from Dt1 and GPID from dt2 should not match in both Datatables
  4. Output we need all the columns from dt1 and dt2

DT1

Mobile Number Employee number Serial Number-Device
94526588 80095530 HW4M4PVQP1
94526671 71064381 DQW6FQCP7T
94526977 71062357 FM9KQX9Y2H
20427 81042932 DMY5VH6TQG
2042754 4175949 JRFGQC0033
242276053 4008970 G7NKVWKJF0
242276966 81155250 N52YXG3G39
242277564 80974212 F17GL0EK0F06
242281339 71040955 Q759FY9HQW
22282788 10179780 LM2V2Y27FM

DT 2

GPID Phone Serial Number
3131704 94526588 HW4M4PVQP1
3170809 94526671 DQW6FQCP7T
3179222 94526977 FM9KQX9Y2H
3188377 68250584 J0Q4DJN4P5
3242193 94699971 JVQ4L9Q3YX
3310459 94699832 QDC25J9JYY
3329297 68950175 X7NV47G92K
3348787 97607668 G7N4PDF7VQ
10030214 46971908 H7307FCWGK
10030214 72512814 LRLFC2X14X

Output

Mobile Number Employee number Serial Number -Device GPID Phone Serial Number
94526588 80095530 HW4M4PVQP1 3131704 94526588 HW4M4PVQP1
94526671 71064381 DQW6FQCP7T 3170809 94526671 DQW6FQCP7T
94526977 71062357 FM9KQX9Y2H 3179222 94526977 FM9KQX9Y2H

@ppr Kindly please help the below query is not working to get the desired output there is no error but output we getting as no records. from above egample 3 records should come with all columns of both datatables.

(From l In dt1.AsEnumerable()
Join r In dt2.AsEnumerable()
On l(“Serial Number -Device”) Equals r(“Serial Number”) _
And l(“Mobile Number”) Equals r(“Phone”)
Where l(“Employee number”).ToString <> r(“GPID”).ToString
Select dt1.Clone().LoadDataRow(l.ItemArray.Concat(r.ItemArray).ToArray(), False)
).CopyToDataTable()

Join Data Table with inner join and set it for Serial Number = Serial Number-Device and Phone = Mobile Number. This gets you a datatable with all columns, where those values match.

Then…

Assign dt_combined = dt_combined.AsEnumerable.Where(Function (x) NOT x(“Employee Number”).ToString = x(“GPID”).ToString).CopyToDataTable

Hi @aravinthan.k , please try this.

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