How to use for each loop with condition

Hello all!

I use invoke code for for each loop . Please correct and tell me the reason why this code is not working

dt.AsEnumerable().ToList().ForEach(Sub(row)     
If Not String.IsNullOrEmpty(row("A").ToString) AndAlso Not in_list.ToLower().Contains(row("A").ToString.ToLower) Then        
row("B") = "WRONG"    
End If     

@Betul_Dundar

can you try this once have passed the argument in_list

For Each row As datarow  In dt.AsEnumerable
If Not String.IsNullOrEmpty(row("A").ToString) AndAlso Not in_list.Contains(row("A").ToString.ToLower) Then 
	row("B") = "WRONG"    
End If
Next



Hi,

as you are updating the datatable, give datatable as in/Out argument in invoke code activity

Hi
Assuming the DataTable is named dt and the in_list is a list of strings, here’s the corrected code:

Dim dt As DataTable
Dim in_list As List(Of String)

’ Initialize the DataTable and in_list here

dt.AsEnumerable().ToList().ForEach(Sub(row)
If Not String.IsNullOrEmpty(row(“A”).ToString) AndAlso Not in_list.ToLower().Contains(row(“A”).ToString.ToLower) Then
row(“B”) = “WRONG”
End If
End Sub)
Use code with caution. Learn more
This code will iterate through the DataTable and check if the value in the A column is not null or empty and is not present in the in_list. If both conditions are met, it will set the value of the B column to “WRONG”.

Hi @Betul_Dundar

Try this code:

For Each row As DataRow In dt.AsEnumerable()
    If Not String.IsNullOrEmpty(row("A").ToString()) AndAlso Not in_list.ToLower().Contains(row("A").ToString().ToLower()) Then
        row("B") = "WRONG"
    End If
Next

Pass dt and in_list as in arguments and map it with variables.

Hope it helps!!

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