I have two sheets in excel with col a and col b in first sheet and col c and col d in second sheet. col b and col c are primary key coloums…I need to compare col a value with col d and if difference is spotted then results needs to be written in third sheet containing col a,col d and col c(at which difference is spotted).Can anyone explain the logic to do this?
example:
col a col b col c col d
abc 1 1 abc
bcd 2 2 zzz
ddd 3 3 qqq
ggg 4 4 ggg
Hi @rahul_kumar4
Try this
(From r1 in dt1.AsEnumerable()
From r2 in dt2.AsEnumerable()
Where r1(“col a”).ToString Equals r2(“col d”).ToString
dt3.Rows.Add(r1(“col a”),r2(“col d”),r2(“col c”))).CopyToDataTable
where the dt3 is the resultant datatable to which output results should be stored
with all columns name being defined
@rahul_kumar4
similar to your case we can do with an inner join:
(From d1 In dt1.AsEnumerable
Join d2 In dt2.AsEnumerable
On d1(“Column2”).toString Equals d2(“Column3”).toString
Where Not d1(“Column1”).toString.Equals(d2(“Column4”).toString)
Let ra = New Object(){d1(“Column1”),d1(“Column2”),d2(“Column3”)}
Select dtResult.Rows.Add(ra)).CopyToDataTable
dtResult is an empty prepared datatable reflecting the column structure of the expected output and can be done e.g. with build datatable