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 January 7th, 2004, 03:50 PM
Authorized User
Join Date: Jan 2004
Location: Half Moon Bay, CA, USA.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default INSERT info into a Access database for display

Bottom Line Question: How do I eliminate this apostrophe problem? Should I run a string search and delete the apostrophe and replace it with Response.Write "´”?

I am trying to create an asp page that will display text that a user submits on a form, and then displays it on another page for customers to read prior to placing an order. I am designing this for a client, since they have limited knowledge of web design, they do not want to get into html coding.

The program takes what they write and puts it in to an Access database, and then another asp page calls it up prior to placing an order.

Everything works, "almost" except for when the client enters text with an apostrophe.

You can find the working site at (This allows the user to enter info, which will be password protected in the future):

Then it is displayed on (prior to a customer placing an order):

Everything works until an apostrophe is entered anywhere in the field.

Here is the code for this page:

  Option Explicit
  Dim strConnect

<title>Place Order Update</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="text.css" rel="stylesheet" type="text/css">
  Const adOpenKeySet = 1
  Const adOpenOptimistic = 2

  Dim objCmd, intNoOfRecords
  set objCmd = Server.CreateObject("ADODB.Command")

  Dim strTitle, strCDate, strCopy, strSQL
  strCDate = Request.Form("currentdate")
  strTitle = Request.Form("title")
  strCopy = Request.Form("copy")

  objCmd.ActiveConnection = strConnect
  objCmd.CommandText = "DELETE FROM PreOrder WHERE ID LIKE '1' "
  objCmd.Execute intNoOfRecords
  'Response.Write "This Update command has affected " & _
                   'intNoOfRecords & " records<br><br>"

  strSQL = "INSERT INTO PreOrder (CDate, Title,Copy) VALUES " & _
             "('" & strCDate & "','" & strTitle & "','" & strCopy &"');"
  objCmd.CommandText = strSQL
  objCmd.Execute intNoOfRecords
  Response.Write "This Record Update command has affected " & _
                   intNoOfRecords & " records<br><br>"

  set objCmd = nothing

Old January 7th, 2004, 04:02 PM
Friend of Wrox
Join Date: Jan 2004
Location: , , USA.
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts

Use VbScript Replace function for all the Request.Form variables:

Or a use a function like this

Function Fix_String(varString)
    if isnull(varString) then
        Fix_String = ""
        Fix_String = trim(varString)
        Fix_String = Replace(Fix_String,"'","''")
    end if
End Function
Old January 7th, 2004, 04:25 PM
Authorized User
Join Date: Jan 2004
Location: Half Moon Bay, CA, USA.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts

Thank you shahchi1, the VbScript function works like a charm. I don't think there are any other characters that interrupt this code. I guess I will have to keep testing it!

Similar Threads
Thread Thread Starter Forum Replies Last Post
INSERT into Access Database from VBA for Excel zuerlein Excel VBA 0 June 3rd, 2007 01:51 AM
Insert row into MS-ACCESS database ITladybug ADO.NET 1 January 28th, 2006 07:57 AM
INSERT string into a Microsoft Access Database gsolis Classic ASP Databases 1 December 31st, 2003 05:31 PM
HELP! How do I insert info. to a database? nvillare VB.NET 2002/2003 Basics 4 December 2nd, 2003 01:44 PM
HELP! How do I insert info. to a database? nvillare VB Databases Basics 0 November 30th, 2003 04:09 PM

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