Need help with Nested for each

Hi all ,
I want to check DT1 column contains value of column from another DataTable and if it returns Yes ,then I need to update one value , can you please help me to do this in C# Linq query .

For Example

output DT should be

if DT1[“Name”] contains DT[“Name”]
then I should Assign DT1["Address]=DT2[“Address”]
I could do that with foreach loop , but its taking more time because of huge data .
Thank you.


try this :

DT_1.AsEnumerable.Join(DT_2.AsEnumerable, row1 => row1["Name"],row2 => row2["Name"],(row1, row2) => { row1["Address"] = row2["Address"]; return row1; }).ToList;


Hello @Manchu

  1. Assign activity:
    Function(row1) row1(“Name”).ToString(),
    Function(row2) row2(“Name”).ToString(),
    Function(row1, row2) Tuple.Create(row1, row2))
    .Where(Function(pair) Not String.IsNullOrWhiteSpace(pair.Item1(“Name”).ToString()) AndAlso Not String.IsNullOrWhiteSpace(pair.Item2(“Name”).ToString()))

  2. For Each activity (TypeArgument: Tuple(Of DataRow, DataRow)):
    a. Assign activity:
    pair.Item1(“Address”) = pair.Item2(“Address”)

Thanks & Cheers!!!


var updatedDT1 = DT1.AsEnumerable()
dt1Row => dt1Row[“Name”],
dt2Row => dt2Row[“Name”],
(dt1Row, dt2Row) => {
dt1Row[“Address”] = dt2Row[“Address”];
return dt1Row;

Try this linq query


Try this Linq:

DT_1.AsEnumerable.Join(DT_2.AsEnumerable, row1 => row1[“Name”],row2 => row2[“Name”],(row1, row2) => { row1[“Address”] = row2[“Address”]; return row1; }).ToList;

Hi @Manchu
Use Invoke VBA Code activity and use the below code
Dim nameToSearch As String = row1(“Name”).ToString()
Dim matchingRow = DT2.AsEnumerable().FirstOrDefault(Function(row) row(“Name”).ToString() = nameToSearch)
If matchingRow IsNot Nothing Then
row1(“Address”) = matchingRow(“Address”)
End If
End Sub)

nameToSearch= Variable is used to search for a matching row in DT2
** Take In argument for nameToSearch varibale (Value to match in DT2)
** Set the Argument for both DT1 & DT2 with In/Out Argument.

Hope this will help you.


Hey Yogeesh ,
I tried it on my code it is not working .will it check dt1Row[“Name”] Contains (dt2Row[“Name”]),but it checks dt1Row[“Name”] ==dt2Row[“Name”]

What if two different people are both named Alison but with different last names?

Hi ,
It dosen’t matter , this is just an example .

Hi @Dilli_Reddy , I want to check dt1Row[“Address”].Contains(dt2Row[“Address”]); , How can I write this in Linq.