Check array present in any datarow of datatable

I am trying to check if all values of my array are present in datarow.
I have array like myArray={“test”, “test1”,“test2”} and i want to check if these all 3 values are present in datarow or not.
I am failing to do it as:

  • Loop through each row
  • Check if myArray.Intersect(row.ItemArray).Count = myArray.Count
    But in above if statement i am getting error as i am unable to convert row.ItemArray to type string array.

Any leads would be appreciated.

@shantanu.khaladkar
Give a try on:

myArray.Intersect(row.ItemArray.Select(function (x) x.tostring).ToArray).Count = myArray.Count

Because row.ItemArray returns Object(), You have to convert it by String()

myArray.Intersect( Ctype(row.ItemArray, String()) ).Count = myArray.Count

1 Like

This worked.
Actually, it was not showing .ToArray for Select by default so I was not trying. But, I just copy pasted and it worked. Anyways, thanks.

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