Solved

Single Quote as SQL String Delimiter

Posted on 2002-05-10
1
147 Views
Last Modified: 2011-10-03
I'm using VB6 against an sql server database.
I use a single quote to string together my sql statements and,as you can imagine, if a user enters a string with a single quote in it, the statement bombs in sql server.

For example,
Here's the completed string:

update Programs set agencycode = 'INSUR', programcode = 'XTS', description = 'Stock Workmen's Compensation Security Fund', sequence = '5', lastactionuser = 'Trapatsos      ', lastactiondate = getdate(), recordstatus = 'Active ' where id = 207

and the string chokes with:
"Incorrect syntax near 's'"

Does anyone have the best advice for stringing together sql statements with values that may contain single quotes?

Thanks in Advance

John
0
Comment
Question by:jtrapat1
1 Comment
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 100 total points
ID: 7002048
Replace single quotes with two quotes.

Dim sValue As string
sValue = "Stock Workmen's Compensation Security Fund"
sValue = Replace(sValue, "'", "''")

Anthony
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 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