I had to Filter a datatable with the following condition:
NDDCurrent_Day_DT.Select(“([Statut] is Null or [Statut] =‘’) AND ([Motif de traitement] is Null or [Motif de traitement]=‘’) AND ([Motif de rejet]= ‘Absence de Motif’)”).CopyToDataTable
i want to keep data with column “Statut” empty and [Motif de traitement] is empty and Motif de traitement] is empty and “Motif de rejet” is Absence de Motif
I’m not sure because you look like you did it right, however I’m not that good at using that syntax. You can try using the datatable as an enumerable instead.
It would look like this: NDDCurrent_Day_Rows = NDDCurrent_Day_DT.AsEnumerable.Where(Function(r) r("Statut").ToString.Trim="" And r("Motif de traitement").ToString.Trim="" And r("Motif de rejet").ToString.Trim.ToUpper="ABSENCE DE MOTIF" ).ToArray
Then, check that it found rows in an If condition: if NDDCurrent_Day_Rows.Count > 0
Reason you need to check the count of your array of rows is because if it found no matches, then it will throw an error if you try to use filtered dataset.
EDIT: you don’t need to check the count, if you just use it in a ForEach though to process the items.
Thanks. I was just wondering.
I’m still not entirely sure it’s true nor needed (atleast in this case).
For example,
If var is Nothing, it will fail right? cause the variable has not been assigned anything. And if it is an empty string or one with whitespaces, var.Trim=“” would check the empty string.
But in the original posters question, he is looking at row items, and each one will always be either a string or an empty string.
So just to rehash, even if the variable has nothing in it, the isnullorwhitespace will throw an exception because the variable would have nothing to look at. But, correct me if I’m wrong… so, the empty string can be checked by looking at its value if it is empty string or not. When would a string variable ever be null where looking at the empty string would not work?
I went ahead and researched some info on null values to get a better understanding. Thanks.
I think it’s just that null is never really used, and when it’s a datatable, the row has empty strings, not nulls.
Interesting. There is indeed some confusion around nothing,empty and null. If I’m correct, u believe empty is uninitialized variant, nothing not referenced to An object and null An unknown value.
Yeah there is indeed confusions for me anyway. Nothing is when nothing is referenced, Null is just no value, and empty string is “”
Technically, I guess you could assign row(0) = null, and it would be a null value, but majority of the time you can do row(0) = “” or string.empty. So I guess it’s up to the developer on how they manage value initialization.