Link to home
Start Free TrialLog in
Avatar of Gani tpt
Gani tpt

asked on

LINQ - How to check and get unmatching row values from tw0 datatable

Hi,

I have two data table and i want to return duplicate rows in second table if any duplicate found for same combination.

if does not match rows then it should return as below

User generated image
the above example empno and sub1 from TAB1 should check in TAB2.

if both match then no need to worry.

if doesn't match the particular row (101 and A) then we should return rows from TAB2

below is my sample code.

but, it shows some error..

where is problem in my code...?

 foreach (DataRow row in dt1.Rows)
         {
            EmpNo = row["EmpNo"].ToString();
            Sub1 = row["Sub1"].ToString();

            var duplicates = dt2.AsEnumerable()
            .GroupBy(dr => row["EmpNo"].ToString() && row["Sub1"].ToString())
            .Where(g => g.Count() > 1)
            .Select(g => g.First())
            .ToList();

            
         }

Open in new window


pls. check my code...?
Avatar of Norie
Norie

From the 2 tables you show what would you want to return?
Avatar of Gani tpt

ASKER

i want to compare empno from tab1 to tab2.

if any empno found in tab2 then return corresponding sub1.

if tab1 of sub1 = tab2 of sub1 is equal then doesn't matter.

if tab1 of sub1 = tab2 of sub1 is doesn't equal then return "Subject " + A1" (A1 doesn't match)....
Sorry, I don't follow - do you want to return rows that match or rows that don't match?
return don't match rows...
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes. Ofcourse it's matching.
Yes. it's working...
Great, have a good day.