Contains / Not Contains clause in Query statement

I try to make a select from a datatable but I have errors.

First, I create a List of String and try to use Contains operator:

dtInJobData.AsEnumerable.Where(Function( r) (r(“ID”).toString<>"" And r(“Etat”).toString.Contains(listNotInSQL)).CopyToDataTable


variable: listNotInSQL
variable type: List < String >
and Default Value: New List(Of String)(New String(){“Terminé”,“En attente”})

but I always have the message Assign: The source contains no DataRows, and it’s not correct.

Secondly, I try to use !Contains operator:

dtInJobData.AsEnumerable.Where(Function( r) (r(“ID”).toString<>"" And !r(“Etat”).toString.Contains(listNotInSQL)).CopyToDataTable

with the same List
and I don’t understand the error message:
Leading ‘.’ or ‘!’ can only appear inside a ‘With’ statement

Thanks in advance

1 Like

instead of ! symbol mention as NOT
the expression be like this
dtInJobData.AsEnumerable.Where(Function( r) NOT r(“ID”).toString.Equals(String.Empty) And NOT listNotInSQL.Contains(r(“Etat”).ToString)).CopyToDataTable

Cheers @Gmatmut

1 Like

Bon Jour @Gmatmut

You are close to solution. Just confirm my understanding:

You want to check if a particular column value is not null or empty and is a containee of your listNotInSQL string list, right?

So give a try on:
dtInJobData.AsEnumerable.Where(Function( r)
not String.IsNullOrEmpty(r(“ID”).toString) And listNotInSQL.Contains(r(“Etat”).toString)).CopyToDataTable


The two answers do what I need.
Thank you very much for your help both of you and I’m sorry for responding so late.

1 Like

Cheers @Gmatmut

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