Solved

Insert single quote in Classic ASP

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

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 32

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with stored procedure 30 59
Update table value with join syntax 2 62
Summernote required 3 104
Using Classic ASP inside HTML pages 2 56
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…
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/…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now