Insert Into FoxPro Error - Value has Single Quote

OK, I need help with this one!

I'm inserting records into a FoxPro Database they are all string values so I have a single quote around each value like so:


However one of my values (name) has a single quote in it and is causing an error trying to insert into the table...for example:

The Real value is Da'Anglio

So how can I insert this record?

Who is Participating?
adriankohwsConnect With a Mentor Commented:
You cannot declare string in the SQL Statement itself like  'My'God', it won't work. If you have single quotes, use parameter to insert.

Working example:

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Query As String = "INSERT INTO StringTB VALUES(@kkk)"
        Dim eCmd As New SqlCommand(Query, Conn)
        Dim str As String = "My'God"
        eCmd.Parameters.Add(New SqlParameter("@kkk", str))
        Catch ex As Exception
        End Try
    End Sub
käµfm³d 👽Connect With a Mentor Commented:
Turn any internal single quotes into double-single quotes.


adriankohwsConnect With a Mentor Commented:
Alternatively, you change the single quote to something else, a special character to insert. So when you retrieving the data, use "Replace" SQL to get back the original text with the single quote.
smithmrkAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.