locked
Problems with ' in INSERT INTO sql statement. RRS feed

  • Question

  • User198610950 posted

    I have a textbox named text1. I use an INSERT INTO sql statement on enter text1's data into my database. But there is a problem. Whenever I use ' in my textbox, I get an error for INSERT INTO statement uses the same ' to enclose string data. The code is like this:

     

    objcmd.InsertCommand = New OleDbCommand
                objcmd.InsertCommand.CommandText = "InSERT INTO dsc ([board],[unique]) values ('" & textbox1.Text & "','" & i & "')"
                objcmd.InsertCommand.Connection = conn

     

                objcmd.InsertCommand = New OleDbCommand

                objcmd.InsertCommand.CommandText = "InSERT INTO dsc ([board],[unique]) values ('" & text1.Text & "','" & i & "')"

                objcmd.InsertCommand.Connection = conn

    The error that I get is:

     

     

    Syntax error (missing operator) in query expression ''"InSERT INTO dsc ([board],[unique]) values ('" & text1.Text & "','" & i & "')"''.

     

    How could I use ' in my text in text1 and still use it in INSERT INTO statement?

    Friday, October 22, 2010 6:17 AM

Answers

All replies