Search code examples
vb.netdatatablerowfilter

How to apply a format in a DataView row filter?


I want to search through my DataTable as I used to with SQL. I am trying to make the row filter ignore numbers that fit these formats: '123-4567-000' or 'SK1234-F1234' ... Here is my current query:

DataView1.RowFilter = "Number NOT LIKE '___-____-___' AND Number NOT LIKE '______-_____'"

Although, the row filter as such will still return results where the number looks like this: 450-0034-00X or 350-3303-04B and etc. I don't want these results to show up (hence the NOT LIKE).

SQL can currently apply this query and omit results that would normally contain the format mentioned above.


Example

Below is a list of numbers in my Dataview. Using the format with the row filter, two of them would be omitted and my result set would contain only 4 out of the 6 numbers.

4500
340034
44393
450-3403-00X 'Should not show up
34321
SK1234-F1234 'Should not show up

How can I recreate that in a DataView's row filter? Is it possible to apply a format with a row filter?


Solution

  • Found an answer to the problem but any other solutions are welcomed!

    For example, the numbers who are similar to '450-3403-00X' will get omitted using this query:

    "NOT (substring(Number,4,1)= '-' AND substring(Number,9,1)= '-')"
    

    This simply verifies if we have a dash at position 4 and position 9 ... Makes it work!

    Still very curious if there are other ways to accomplish this.