Solved

Insert Into FoxPro Error - Value has Single Quote

Posted on 2013-06-07
4
487 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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