Solved

Insert Into FoxPro Error - Value has Single Quote

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

628 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