Solved

Insert Into FoxPro Error - Value has Single Quote

Posted on 2013-06-07
4
490 Views
Last Modified: 2013-06-11
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:

'value'

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:

'val'ue'
The Real value is Da'Anglio

So how can I insert this record?

Thanks,
Mark
0
Comment
Question by:smithmrk
  • 2
4 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 50 total points
ID: 39229951
Turn any internal single quotes into double-single quotes.

e.g.

'Da''Anglio'
0
 
LVL 10

Accepted Solution

by:
adriankohws earned 450 total points
ID: 39231091
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))
        Try
            eCmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
0
 
LVL 10

Assisted Solution

by:adriankohws
adriankohws earned 450 total points
ID: 39231093
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.
0
 

Author Closing Comment

by:smithmrk
ID: 39238659
Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question