SilverShotBee SilverShotBee - 11 months ago 122 Question

VB.Net Multiple Criteria For Datatable.Select Command - Including Wildcard

I'm using the following code to count how many times a string appears in a column of a


Dim numberOfRecords As Integer = DS.Select("[Owner Name] = 'Test Name Here'").Length

Is there a way of adding a second, or third criteria to the command? Currently I have to loop through each row to do multiple criteria. I've tried inserting an 'AND' but the code then fails.

Dim numberOfRecords As Integer = DS.Select("[Owner Name] = 'Test Name Here'" And "[Owner Number] = '000999888777'").Length


I realise that I hadn't put the
inside the string, and doing that has solved that problem. But now I have a new one.
My code now looks like this:

Dim numberOfRecords As Integer = DS.Select("[Owner Name] = 'Test Name' And [Owner Number] = '000999888777' And [Owner Email] = '%%'").Length

I was hoping that the "%%" would result in any string being accepted as the correct criteria and resulting in a count on the length, but it doesn't (As I'm sure I've seen that "%%" is a wildcard to any value somewhere!). Is there a way to effectively allow any value to pass as the correct criteria?

I understand that I could omit it from the string, but I have a large criteria set of over 40 of these and it would be extremely handy to be able to leave a wildcard that always gets accepted unless the criteria needs to be used. That way I can build a function and simply pass the variables I want to use.

Hopefully there's a method to accommodate what I am trying to do?

Answer Source

By using [Owner Email] = '%%' it will search for an email that looks exactly the same. Rather try using 'Like', as in [Owner Email] LIKE '%%'.