Reputation: 2157
How can I use regular expressions in an OleDB connection? I tried this:
Dim conn As New OleDbConnection
conn.ConnectionString = "my little secret"
conn.Open()
Dim cmd As New OleDbCommand( _
"SELECT * FROM books WHERE title REGEXP '^.*[a-z][a-z][0-9].*$'", cmd)
Dim dt As DataTable = cmd.ExecuteQuery()
but it results in a syntax error (missing operator).
Upvotes: 0
Views: 511
Reputation: 1086
If you are trying to get all the books with title contain word hello
then you can use sql LIKE
operator you don't need regex, just change your sql command to this,
"SELECT * FROM books WHERE title Like '%hello%' "
Update:
If you're not using some complex regex then i still suggest to go with LIKE operator, see some examples here. And if you have to have regex then you can create a function in Vb.Net and import the dll into sql server as CLR function
and use that, see details
Upvotes: 1