Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - SQL update problem

Reply
 
Old 01-03-2009   #1 (permalink)
Patrick D.


 
 

SQL update problem

C#, webapplication

Hi

usually this sql update command works fine:
(html is a memo-field)

UPDATE [Table1] SET [html]='content of a memo-field' WHERE [ContentID]='1'

As soon as I have a content like

'winter' is colder than "summer"

to assign to the html-field the sql-statement produces an error since the
little signs around winter and summer are a problem for the sql-statement.

Server.HtmlEncode(String) didn't help.

What do I need to do, to be able to assign any text-contents to the
memo-field?

Thanks for your help.

Patrick



My System SpecsSystem Spec
Old 01-03-2009   #2 (permalink)
Göran Andersson


 
 

Re: SQL update problem

Patrick D. wrote:
Quote:

> C#, webapplication
>
> Hi
>
> usually this sql update command works fine:
> (html is a memo-field)
>
> UPDATE [Table1] SET [html]='content of a memo-field' WHERE [ContentID]='1'
>
> As soon as I have a content like
>
> 'winter' is colder than "summer"
>
> to assign to the html-field the sql-statement produces an error since the
> little signs around winter and summer are a problem for the sql-statement.
>
> Server.HtmlEncode(String) didn't help.
>
> What do I need to do, to be able to assign any text-contents to the
> memo-field?
>
> Thanks for your help.
>
> Patrick
>
The preferrable way to handle this is to use a parameterised query. Then
you don't have to worry about encoding the string.

UPDATE [Table1] SET [html]=? WHERE [ContentID]='1'

Add a parameter to the command object. Example:

cmd.Parameters.Add("", OleDbType.VarChar, 0).Value = "'winter' is colder
than \"summer\"";

If you can't use parameters, you have to encode the string when you put
it in the query. This is done differently depending on what database you
are using. Here are some of the most common:

SQL Server: replace ' with ''
MS Access: replace ' with ''
MySQL: replace \ with \\, then replace ' with \'

--
Göran Andersson
_____
http://www.guffa.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
HP UPDATE FIRMWARE update problem? Drivers
Update Problem Vista performance & maintenance
Comodo Firewall update addresses Windows Update problem Vista security
Comodo Firewall update addresses Windows Update problem Vista General
Huge problem with security update kb935902 on Windows Update Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46