Add Regex string to database

OSVBNET 1,386 Reputation points

Hello, I have a regex string (near 500 characters) so I created a table for it, since Short String is up to 255 chars I set it to Long String (Memo)
But I can't add it to the db:

OleDb.OleDbCommand("UPDATE MyData SET RegexString = '" + vRegexString + "'", MyConnection)

Syntax error (missing operator) in query expression ''^(([....

Well how can a regex get saved due to its varying chars?
Thank you for helping :)

An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,596 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 112.9K Reputation points

    It seems that you are using the unrecommended and dangerous string concatenation. Try using parameterised queries, something like this:

    Dim cmd = new OleDb.OleDbCommand("UPDATE MyData SET RegexString = ?", MyConnection)  
    cmd.Parameters.AddWithValue( "s", vRegexString)  

    There are more approaches that are described in documentation.