Regular Expressions in dataview.rowfilter

G

Guest

According to what I see in the manuals I should be able to use regular
expressions with the rowfilter property of a dataview but I keep getting
errors.
Example:
I want to find any rowview where column APCode is not a string of exactly 3
uppercase letters.
Assume dtBAirpt is an instance of a datatable having a column APCode
Code snippet
Try
Dim dvTest As New DataView(dtBAirpt, _
"APCode NOT LIKE '[A-Z][A-Z][A-Z]'", "APCode", _
DataViewRowState.CurrentRows)
If dvTest.Count > 0 Then
For iLoop = 0 To dvTest.Count - 1
oRV = dvTest.Item(iLoop)
sRowInfo = FmtRowInfo(oRV)
AddErrorRow("INVLD STATION", sRowInfo, "ERROR")
oRV.Delete()
Next
End If
Catch ex As Exception
Console.WriteLine("Error: " & ex.Message)
End Try



Console:
Error: Error in Like operator: the string pattern '[A-Z][A-Z][A-Z]' is
invalid.

If I change the string pattern to '???' I can successfully test for 3
characters but that does not address the uppercase.

Anyone know how, or if it is possible to use a regular expression in a
dataview.rowfilter property?

Regards,
Erik
 
J

Jay B. Harlow [MVP - Outlook]

Erik,
The DataSet object model supports a very limited regular expression syntax.
To see what expressions are supported look at the DataColumn.Expression
topic.

It appears that the Like operator only supports "*" and "%". I don't see "?"
listed, so I'm really not sure what it is matching. When I try "?" with Like
it has not effect that I can see...

Square brackets "[" and "]" are actually used to escape special characters,
rather then define a set of characters... For example to search for
literally * in a column you would use:

Like '*[*]*'

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top