Linq To Compare 2 or 3 Column Within 1 DT

Hi, I have 1 DT with 7 column in it, I have to compare 6 Columns and write the result in column “Result”

I try to use linq but I facing some error, wich the result is null even the data is matching, and I dont know how to write the result in column “Result”
Function (row)
row(“ColumnA”).ToString.ToUpper.Trim.Equals(row(“ColumnB”)) And
row(“ColumnC”).ToString.ToUpper.Trim.Equals(row(“ColumnD”)) And
row(“ColumnE”).ToString.ToUpper.Trim.Equals(row(“ColumnF”)) And
Can you help me about my linq? Thank you and hope you understand what I’am saying because my english is bad.

Hello, you can try this code

(From d In dt.AsEnumerable
Let u =If(d(0).toString.equals(d(1).toString) And d(2).toString.equals(d(3).toString) And d(4).toString.equals(d(5).toString),“MATCH”,“NOT MATCH”)
Select dt.clone.Rows.Add(New Object(){d(0),d(1),d(2),d(3),d(4),d(5),u})).CopyToDataTable

Hi, thank you for reply, What if I want use Column Name instead of index? can I just replace the index with column name?

When it is about updating a data column we keep in mind the potential and also limitation of LINQ e.g used within an Assign or increasing Black Boxes e.g. applied within an invoke code.

Good strategies are also to run for hybride approaches like comining for each row and LINQ within the execution block

Coming back to the part for ColA,B - ColC,D - ColE,F checks

check1 =

{"Column A", "Column B"}.Select(Function (x) row(x).ToString.ToUpper.Trim).Distinct().Count = 1


{"Column C", "Column D"}.Select(Function (x) row(x).ToString.ToUpper.Trim).Distinct().Count = 1

check3 =

{"Column E", "Column F"}.Select(Function (x) row(x).ToString.ToUpper.Trim).Distinct().Count = 1

And then we can calculate the matching info by:
matchText = IF({check1,check2, check3}.All(Function (x) x), “Matching”, “not matching”)

sure you can replace with your column name

Hi thank you for reply, I want to use linq to replace for each row activity as much as possible, is that a bad approach?

Thank you, have a nice day!

you can read this article

answered with

Also discussed on a few posts here in the forum e.g.

and in the blog

We would always recommend to define formal criterias on approach selection and then a decission what to use or not can be derrived from.