Find rows corresponding to items in a list

I have a list called “CorrectList”, and a table called “WorkDT” with a column called “containerID”.
All the items in the list are container ids, and I would like to get all and the entire rows that have corresponding container ID as the list, preferably without using for each loop.
Please help, thank you

Hi @Joanne_Chang_LAX ,

Maybe could you give a Try for the below Approach :

UpdatedDT = WorkDT.AsEnumerable.Where(Function(x)CorrectList.Contains(x("containerID").ToString)).CopyToDatatable

Also, When there are no rows match, CopyToDatatable() gives out Error, we could handle as mentioned below :

If the above doesn’t work, could you provide us with a more details on the Data representations or Provide us with Sample Data and Expected Outputs.

I’ve checked the WorkDT, and the whole datatable is in it, so there should be datarows

Create DT_CorrectList

  • For Each Row in CorrectList
    ** Add Data Row

This gets CorrectList into a datatable.

Then you can use Join Data Table (left) to join WorkDT with DT_CorrectList. Then you can use Filter Data Table on WorkDT to get rid of any rows that don’t have a containerID

@Joanne_Chang_LAX ,

Is it also possible to show us the WorkDT in the same way from Debug Panel, just so we can confirm ?

Sorry there are some company information in there…

I can only give you this to show there are items in there

But WorkDT also have container ID, I’m trying to find the rows in WorkDT that have the same values as the ones in the list

That’s what Join Data Table does.

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