I have an array “MaterialArray” which has some material numbers inside it. And I have datatable DT.
This DT has a column named “Material Number” and there are material numbers written. I want to remove the rows where the “Material Number” column contains a value which is present in the Array.
Ex:
MaterialArray= [“A”,“B”,“C”,“D”]
DT
Material Number
A
B
C
D
E
After the execution of that code I want a dt:
ResultDT:
Material Number
E
so the rows which material array has the values are removed.
I wrote this code but It is not working properly.
(From r In DT.AsEnumerable
Where Not MaterialArray.Any(Function (x) r(“Material Number”).toString.toUpper.Contains(x.ToUpper))
Select r).CopyToDataTable
Just now checked your Linq expression it was working perfect. Not sure why you are getting issue. Please check how did you created your string array. thanks.
So the thing is when I write the linq expression as “where Not” i get the error that the source contains no dt, saying that there is no rows to the ouput but there is actually 1 row which has a material number that is not present in the array so actually it should return that row.
And when i say “where” it outputs the original DT… it weird
Extra whitespace might exist in Material Array. For now, can you try the following expression?
(From r In DT.AsEnumerable
Where Not MaterialArray.Any(Function (x) x.ToUpper.Contains(r("Material Number").toString.toUpper))
Select r).CopyToDataTable