Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 10th, 2004, 08:35 AM
Authorized User
Join Date: Jul 2004
Location: , , Ireland.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting a value containing ' into a db


Further to my previous question about passing a querystring containing &, I have done further testing and am now having a problem inserting a record into my db when a field contains the apostrophe (').

I have tried using Server.HTMLEncode, but it doesn't encode the '.

Here's the code :
strSQL = "INSERT INTO tblBookCdDvd_Item (Item, [LastPost]) VALUES ('" & Server.HTMLEncode(strItem) & " ', '" & Now() & "')"

And here's the error :
Syntax error in query expression ''' & < > ? ', '11/10/2004 12:37:46 PM')'.

I'm passing ' & < > ? in the Item field... (Ok, I'm really trying to break it - but if I don't, someone else will. Then I'll have people yelling at me.)


Old November 10th, 2004, 08:44 AM
Friend of Wrox
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post

Hey Jennie,

When you are adding string values to your query, replace any apostrophes with two apostrophes...
Replace(strItem, "'", "''")


Old November 10th, 2004, 08:55 AM
Authorized User
Join Date: Jul 2004
Location: , , Ireland.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts

Once again - Thanks Chris!


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting data into DB roserose PHP Databases 1 April 24th, 2006 07:54 AM
Inserting records into DB using DataAdapter favor ADO.NET 4 June 16th, 2005 02:29 AM
How do I check a db before inserting a record? Lucy SQL Server ASP 3 April 25th, 2005 10:47 PM
Inserting into access db using VWD. Peki ASP.NET 2.0 Basics 1 April 11th, 2005 09:12 PM
Keep inserting the same image to DB dcathers C# 2 August 31st, 2004 04:41 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.