473,804 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HtmlEncode and apostrophes

Hi

I'm trying to code up an admin system for my website. A couple of the
welcome text paragraphs are stored in an SQL database, so that we can update
them should we need to. However, even though I'm using the HTMLEncode method
(I've also tried the URLEncode method), the apostrophe always remains, and
then when I try and do the update query, I get...

Unclosed quotation mark after the character string

The SQL is UPDATE StaticPages SET Text = 'blah' WHERE PageID = 'ABOUT'

The code only breaks when the Text variable contains an apostrophe. But, I'm
using an encoding method? Why is the apostrophe not being encoded?

Thanks,
Dan
Mar 31 '08 #1
2 2776
the sql never hits the page, and is not shown - - it's not an HTML/urlEncode
situation - -
you'd need to double the single quotes to get SQL to recognize it, since the
update statement is a string - -
But first - I'd suggest not doing it with concatenation this way - used
parameterized queries:
http://www.aspnet101.com/aspnet101/tutorials.aspx?id=1 (2 part tutorial)
David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
"musosdev" <mu*******@comm unity.nospamwro te in message
news:8E******** *************** ***********@mic rosoft.com...
Hi

I'm trying to code up an admin system for my website. A couple of the
welcome text paragraphs are stored in an SQL database, so that we can
update
them should we need to. However, even though I'm using the HTMLEncode
method
(I've also tried the URLEncode method), the apostrophe always remains, and
then when I try and do the update query, I get...

Unclosed quotation mark after the character string

The SQL is UPDATE StaticPages SET Text = 'blah' WHERE PageID = 'ABOUT'

The code only breaks when the Text variable contains an apostrophe. But,
I'm
using an encoding method? Why is the apostrophe not being encoded?

Thanks,
Dan

Mar 31 '08 #2
Thanks David - Parameterised queries worked first time! A good one to remember!

"David Wier" wrote:
the sql never hits the page, and is not shown - - it's not an HTML/urlEncode
situation - -
you'd need to double the single quotes to get SQL to recognize it, since the
update statement is a string - -
But first - I'd suggest not doing it with concatenation this way - used
parameterized queries:
http://www.aspnet101.com/aspnet101/tutorials.aspx?id=1 (2 part tutorial)
David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
"musosdev" <mu*******@comm unity.nospamwro te in message
news:8E******** *************** ***********@mic rosoft.com...
Hi

I'm trying to code up an admin system for my website. A couple of the
welcome text paragraphs are stored in an SQL database, so that we can
update
them should we need to. However, even though I'm using the HTMLEncode
method
(I've also tried the URLEncode method), the apostrophe always remains, and
then when I try and do the update query, I get...

Unclosed quotation mark after the character string

The SQL is UPDATE StaticPages SET Text = 'blah' WHERE PageID = 'ABOUT'

The code only breaks when the Text variable contains an apostrophe. But,
I'm
using an encoding method? Why is the apostrophe not being encoded?

Thanks,
Dan


Mar 31 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9836
by: James Foreman | last post by:
I've got a set of emails in a table, where sometimes they've failed to input the @ properly. Eg james.foreman'abcmail.co.uk How do I write a replace to deal with that? Also, I've got a set of names in a table, all in lower case. I can easily capitalise the first letter of each name, but if it's somebody like O'Brien, I'd like to get that right too (so need to be able to
3
2769
by: Richard Hollenbeck | last post by:
I have an email field and a command button to send email. The problem is that when the email program opens up there are apostrophes around the email address that I have to manually remove before sending the email. My code is very simple. I can't understand why the apostrophes are put there but the addresses won't work until they are stipped of the apostrophes. Here's my code: Private Sub cmdEmail_Click() If len(txtEmail) > 0 Then
4
10660
by: Andrea Williams | last post by:
I have a class that imports System.Web.UI.Page. The code below works: public string JScriptEncode(string strValue) { strValue = strValue.Replace(@"'", "\x27"); //' JScript encode apostrophes strValue = strValue.Replace(@"""", "\x22"); //' JScript encode double-quotes
3
4114
by: Michael Gaillez | last post by:
Hi, I'm dynamically loading an assembly into an ASP.NET application. In the control that I load from that dynamic assembly I've tried to use Server.HTMLEncode but this results in a serious performance loss. Is there anyone who knows why or is there an alternative for server.htmlencode method? Without the server.htmlencode the thingy works very fine. greetz
4
4685
by: Andy Fish | last post by:
When using databinding, I have gotten into the habit of using single quotes (apostrophe) round attribute values rather than double quotes because this allows visual studio to work when there are quotation marks in the databinding expression. As far as I can tell this seems to be recommended practice. However, I just realised that HtmlEncode doesn't encode apostrophes, so if you do something like this <a href=......
3
2893
by: David Lozzi | last post by:
Howdy, I have my left navigation of Hyperlinks, and part of the link's querystring is the title of the page they are going to. For example, one of the pages is Cars & Trucks. With HtmlEncode, it translates it to Cars%20&%20Trucks. The ampersand is still there. Shouldn't the HtmlEncode translate that? So on the page the title is Cars because its translating the & as a new name/value pair. Any suggestions? Thanks!
1
14569
by: Marco Miltenburg | last post by:
While working on some multilingual code I found a rather strange thing happening with Server.HTMLEncode. While loading different languages I change the Codepage and Charset in ASP to reflect the language. This all works fine. However when I tried to use Charset UTF-8 with Codepage 65001 everywhere I found that HTMLEncode always translates all UTF-8 characters to &#xxxx. Example:
1
2759
by: Alexander Higgins | last post by:
>>Thanks for the response.... Point Taken but this is not the case. Thus, if a person writes a text file on her or his computer and does not use UNICODE to save it, the current code page is used. If this file is given to someone with some other current codepage, the file is not displayed correctly. Simply converting the file to Unicode will make the data display properly. When performing the encoding process the encoding will escape...
4
18506
by: Lucanos | last post by:
Hey Guys, Probably a simple question, but one I am struggling with all the same. I know that in PHP you wrap a text string in apostrophes or quotations - (examples $variable = 'this string' OR $variable = "that string" ). What I am trying to figure is how to handle a string which contains both apostrophes and quotations already. Is there a something like CDATA is for XML?
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.