Solved

Insert Into FoxPro Error - Value has Single Quote

Posted on 2013-06-07
4
493 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

749 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