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
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
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”.
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.