How to match row value using linq and update status column as matched or not matched

i have two datatable, i have to compare row of column1 of dt1 with row column 1 of dt 2

if value of both cell matched i have to update dt1 column Status as matched or not matched

Please help me how to do with Linq


dt1 = (From row1 In dt1.AsEnumerable()
Join row2 In dt2.AsEnumerable()
On row1(“Column1”).ToString() Equals row2(“Column1”).ToString()
Select dt1.Clone().LoadDataRow({row1(“Column1”), If(row2 Is Nothing, “Not Matched”, “Matched”)}, False)).CopyToDataTable()


try with invoke code

For Each r1 As DataRow In dt1.AsEnumerable
For Each r2 As datarow In dt2.AsEnumerable
If r1(0).ToString.trim.Equals(r2(0).ToString.Trim) Then
r1(“status”)=“Not Matched”
End If


Hi @aslam_ali1 ,

Can you please try below code,

DT.AsEnumerable().ToList().ForEach(Sub(row) row(“Column3”) = If(row(“Column1”).ToString = row(“Column2”).ToString, “Matched”, “Not Matched”))

Sandhiya P

Hi @aslam_ali1

You can try this using Invoke Code activity


For Each row1 As DataRow In dt1.Rows
    Dim valueToMatch As String = row1("Column1").ToString()
    Dim matchingRow As DataRow = dt2.AsEnumerable().FirstOrDefault(Function(row) row("Column1").ToString() = valueToMatch)

    If matchingRow IsNot Nothing Then
        row1("Status") = "Matched"
        row1("Status") = "Not Matched"
    End If

Hope this helps!!

@rlgandu getting this error

can u please share the xaml file. Im not understanding
im beginner to Linq


I have two different data table

if possible please share the xaml also


@aslam_ali1 (42.6 KB)


dt1.AsEnumerable.ToList.ForEach(Sub(row) row("Status") = If(dt2.AsEnumerable.Any(Function(dr) dr("Column1").ToString = row("Column1").ToString), "matched", "not matched"))

Try this its helps you :



try this linq query

use add data column to add a column name it as status

dt=(From row In dt1.AsEnumerable()
Let a = If(dt2.AsEnumerable.Any(Function(r) r(0).ToString.trim.Equals(row(0).ToString.trim)),“Matched”,“Not Matched”)
Select dt1.Clone.LoadDataRow({row(0).ToString,row(1).ToString,a},False)).CopyToDataTable


Thank you @lrtetala it is working

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.