suppose I have a table: TABLE_A with a column Col1 char(20)
The value of row 99 for Col1 = "O'DONELL"
Now I construct a dynamic query using a txtBox1.Text = "O'DONELL"
My query:
dim strSQL = " Select * from dbo.TABLE_A WHERE Col1 = ' " & txtBox1.Text & " ' ".
I purposely put extra spaces to see the quotes & double quotes better. The above statement will fail because of the embedded ( ' ) in the txtBox1 variable. I think an update or insert query may work by replacing the 1 single quote with 2 single quotes but I have found that this does not work for me when it is in a where clause. Please include a code sample with your solution.
Start Free Trial