Solved

Single Quote as SQL String Delimiter

Posted on 2002-05-10
1
150 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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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 have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

733 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