Solved

Insert single quote in Classic ASP

Posted on 2014-01-31
4
698 Views
Last Modified: 2014-01-31
Hi Experts,
I'm trying to insert last names like O'Neil into my database, but it gives me an error because of the single quote in the last name.
It works with names without single quotes.
This is how I'm doing it:

sLast_Name=rs2("Last_Name")

Ho can I rewrite this so that it accepts single quotes.

Thank you
0
Comment
Question by:romsom
[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 33

Accepted Solution

by:
Big Monty earned 350 total points
ID: 39824632
easiest way would be to use the replace function in your sql:

sql = "insert into table ( lastname ) values( '" & Replace( sLast_Name, "'", "''" ) & "' )

Open in new window

0
 
LVL 33

Expert Comment

by:Big Monty
ID: 39824637
of course, using parameterized queries would be much simpler and safer to do
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 150 total points
ID: 39824661
I concur 200% with above: parametrized queries are the way to go:
* better security
* better control over data types
* better performance by avoiding to "recompile" the sql each time.
0
 

Author Closing Comment

by:romsom
ID: 39824695
Thank you very much for your help. This also solved the problem:

sLast_Name=replace(rs2("Last_Name"),"'","''")
0

Featured Post

Industry Leaders: 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

Title # Comments Views Activity
Query not working correctly? (or how i want it to... 6 54
innerHTML 7 40
Executing a script on a timer online 5 32
VB script help 23 36
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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