I have two datatables e.g. DT1 and DT2 both have 10 columns initially
I want to compare the values from both the tables also add a column in DT2, if value from DT1 matches the value of DT2 then in the added column in DT2 I need to write “Yes” or if does not match I need to write “No”.
So you want to compare if a row item in DT 1 is equal to row item in DT2 and if both are equal then update “Yes” in newly added column , if not equal then update as “No” right?
As far we had understood is that all columns from dt1 row are to check against columns from dt2 row, but
dt1 will also have an additional newly added row for the result check, right?
dtResult = dt1.Clone
Add DataColumn “Check” to dtResult
Match Check with StringConcat Trick (only working for simple datatypes)
Assign Activity:
dtResult =
(From d1 in dt1.AsEnumerable
let ja = String.Join("", d1.ItemArray)
Let chk = dt2.AsEnumerable.Any(Function (x) String.Join("",x.ItemArray).Equals(ja))
Let rs = If(chk, "YES","NO")
Let ra = d1.ItemArray.Append(rs).ToArray
Select r = dtResult.Rows.Add(ra))).CopyToDataTable
Variations are to work with SequenceEqual method for the check
For hugh datavolumns we would recommend to check the for common/uncommon rows with the Intersect / except LINQ operator and building the smallest list of result rows
then loop and check if loope row is contained/Not contained within the check list
Thanks a lot @ppr , I will try this whereas to inform the data size is huge like 500K+ rows, as you mentioned if you have any other efficient approaches for that please help on that as well.
I will also try to share some input and output data for reference.
Can you please guide on what are the complex types that might be which i can cehck accordingly in data.