Hello,I’m having trouble in filter datatable based on two conditions in two columns.
For example, my data table looks like:
Location Type
AU AA
JP BB
CN EE
HK CC
CN AA
CN CC
JP DD
HK DD
CN DD
And the condition is: Remove the rows where
- Location = “CN” AND
- Type = “AA” or “CC”
Note that the row need to be removed if and only if the two conditions are met.
So the output should be like:
Location Type
AU AA
JP BB
CN EE
HK CC
JP DD
HK DD
CN DD
I’ve tried this query:
(From r In myDT.Select()
Where (r(“Location”).ToString <> “CN” And
(r(“Type”).ToString <> “AA” Or r(“Type”).ToString <> “CC”))
Select r).CopyToDataTable
but it always turns out that all the “CN”'s are removed.
I also tried to use ‘for each row’ and if statement to find rows that met the two conditions, but I stuck in remove those rows from Data Table.
Could anyone help me with this? Thank you!