Solved

Insert single quote in Classic ASP

Posted on 2014-01-31
4
645 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
  • 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 142

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Group by correlation 4 58
ASP Sessions Being Cleared/Modified 6 80
Summernote required 3 141
Index on a Table 6 15
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

809 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