Need a linq query to solve this issue

I want a linq query to check if all values in a datarow are “NoChange”, if yes then its should give “OK” or else “Error”

eg if(CurrentRow.ItemArray.Any(Function(x)x.ToString.Equals(“NoChange”)),“Error”,“OK”)

Hello @P-A-J, try something like this:

Dim allNoChange = CurrentRow.ItemArray.All(Function(x) x.ToString().Equals(“NoChange”))

Dim result As String = If(allNoChange, “OK”, “Error”)

Why bother with an extra variable? Just do it all with an If expression…

If(CurrentRow.ItemArray.All(Function(x) x.ToString().Equals(“NoChange”)),"OK","Error")

1 Like

Can you make it such that i can decide the range of columns to be checked for the status , “Ok” or “Error”

Hi @P-A-J ,

Could you let us know the Columns name list that you want to check the value as “OK” ?

If(CurrentRow.ItemArray.All(Function(x) x.ToString().Equals(“NoChange”)),“OK”,“Error”)

Can you modify it such that if all values in a row are “NoChange” , only then it should give “OK” , otherwise “Error”

@P-A-J ,

I believe the expression provided does the same operation. Are you not getting the expected output ? Maybe there are space before/after NoChange, hence it is not recognised. So we can use Trim and then perform operation :

If(CurrentRow.ItemArray.All(Function(x) x.ToString.Trim.Equals("NoChange")),"OK","Error")
1 Like

I want to exclude column ID in this linq query

@P-A-J ,

From one of the Other Posts we got to know there was Validation column also involved.

So we can check the below modified Expression :

If(DT.Columns.Cast(Of DataColumn).Where(function(x) Not {"ID","Validation"}.Contains(x.ColumnName)).All(Function(x) CurrentRow(x.ColumnName).ToString.Trim.Equals("NoChange")),"OK","Error")
1 Like

Its working thank you

1 Like

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