Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 7th, 2004, 03:41 PM
Authorized User
 
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default Apostrophe in textarea

Hi, I have a multiline textbox on my web form. whenever I use apostrophe in the text, I get an error. e.g if I am using the word party's, the error would be:-

Incorrect syntax near 's'. Unclosed quotation mark before the character sring".

does that mean I need to parse my string to check if any quotes/apostrophe has been used OR there is a way where I can tell to allow any kind of data in the textbox?

Thanks
Renu

 
Old September 7th, 2004, 11:13 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to find ' and replace with '' otherwise SQL will throw it back at you. If you use command parameters on your command object, you can safely assign the parameter values directly from the source controls and not need to manually handle the apostrophies.
 
Old September 8th, 2004, 01:46 PM
Authorized User
 
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I wrote a function to replace all single quotes with double and it worked. But, I don't get what you mean by "command parameters on command object". Just for my own curosity I would like to know if there is any other way to accomplish the same thing.

Thanks


 
Old September 8th, 2004, 02:13 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Well, seeing as you posted this message in the ASPX forum, I'm assuming that you are using some ADO.NET classes to make database calls. For example: System.Data.SqlClient.Connection and System.Data.SqlClient.Command. The Command objects for the SqlClient as well as the other native .NET database clients have a parameters collection into which you add an instance of the appropriate parameter class. When you assign one of these parameters a value, the class itself handles the escaping of the necessary SQL characters. So you can create a query: "UPDATE MyTable SET myField = @myParameter", then set the parameter "@myParameter" value to "mc'value" and the parameter class or the command class (which one is really irrelevant) will automatically generate the correct complete SQL string: "UPDATE MyTable SET myField = 'mc''value'"





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you translate an apostrophe? IronStar XSLT 2 November 13th, 2006 12:35 PM
cdonts and apostrophe bostonrose Classic ASP Components 3 October 23rd, 2006 08:20 AM
Apostrophe in a textarea myself Classic ASP Professional 9 June 8th, 2006 07:32 AM
Javascript validation for apostrophe crmpicco Javascript How-To 2 March 2nd, 2005 06:57 AM
display vbCrLf's from textarea to textarea mat41 Classic ASP Basics 8 June 10th, 2004 12:19 AM





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