Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Single Quote as SQL String Delimiter

Posted on 2002-05-10
1
Medium Priority
?
153 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
[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
1 Comment
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 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