Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics 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 September 21st, 2006, 08:43 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Forgotten escape character

I have an ASP page in which I need to query an Access database for names. Below, I have the current query I'm using. Unfortunately, it doesn't work for names like O'Malley and D'Amour because I'm using the single-quote to separate my string values in the SQL string.
It's been a while since I've coded ASP and I've forgotten how to escape the ' character so that it will be able to go through the DB.

strSql = "Select * From Students Where FirstName='"&fName&"' AND LastName='"&lName&"'"

Can someone please help?

Chris

 
Old September 21st, 2006, 08:51 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Chris,

Just replace any apostrophes (') with two apostrophes ('').

HTH,

Chris

 
Old September 21st, 2006, 10:39 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, I got it. Thank you.

 
Old December 4th, 2006, 08:48 AM
Registered User
 
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi the solution to ur query is as follows

strSql = "Select * From Students Where FirstName='"&Replace(fName,"'","''")&"' AND LastName='"&replace(lName,"'","''")&"'"

 
Old December 4th, 2006, 09:37 AM
Registered User
 
Join Date: Jul 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to miketayo
Default

to be professional just write a function like this and pass your variables to it;

Public Function ReplaceString(ByVal strString As String) As String
        Return strString.Replace("'", "''")
End Function

And use it like this

strSql = "Select * From Students Where FirstName='" & ReplaceString(fName) &"' AND LastName= '" & ReplaceString(lName)& "'"









Similar Threads
Thread Thread Starter Forum Replies Last Post
escape character for double quotes Andy dg C# 2005 3 March 15th, 2007 10:51 PM
Forgotten Password pompey BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 28th, 2005 06:55 AM
asterisk escape character theboylatham Access VBA 3 August 13th, 2005 02:18 AM
Need Escape Character? shaileshmark SQL Server 2000 5 July 20th, 2004 12:35 PM





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