Insert single quote in Classic ASP

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:


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

Thank you
Who is Participating?
Big MontyConnect With a Mentor Senior Web Developer / CEO of Commented:
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

Big MontySenior Web Developer / CEO of Commented:
of course, using parameterized queries would be much simpler and safer to do
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
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.
romsomAuthor Commented:
Thank you very much for your help. This also solved the problem:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.