Search code examples
vb.netlinqinversion

Linq where 'not like' or ! <> equivalent in


I've got this working :

Dim locations = From row In allLocations.AsEnumerable()                  
Where row.Field(Of String)("PartNr") Is Nothing
Select row

It gets all the locations where there is no partnumber. But i would like to do something like this to get everything except some record(s):

Dim locations = From row In allLocations.AsEnumerable()                  
Where row.Field(Of String)("PartNr") Not Like "12345"
Select row

Solution

  • I've found a solution for what i was looking for:

    Dim rgx As New Regex("^G[A-Z]")
    Dim alleLocaties = From row In beginQuery.AsEnumerable()
                       Where (Not rgx.IsMatch(row.Field(Of String)("Location")) 
    

    In this example i get all the locations that do not start with G followed by a letter.