Solved

Insert single quote in Classic ASP

Posted on 2014-01-31
4
753 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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