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
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...?
pls. check my code...?
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
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();
}
pls. check my code...?
From the 2 tables you show what would you want to return?
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)....
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?
ASKER
return don't match rows...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes. Ofcourse it's matching.
ASKER
Yes. it's working...
Great, have a good day.