Wednesday, March 21, 2012

Is this an SQL problem?

Hi,

I've got a FormView to enter data into a MS SQL Server DB.But when I'm entering text like this (which gets saved into a textfield in the DB):

I'm just a guy.

And I'm standing here.

and then later try to display it again, I get:

I?m just a guy. And I?m standing here.

The apostrophe gets turned into a question mark. And the line feeds vanish or get ignored.

What's wrong and how do I prevent this?

Thanks a lot,

Jerome

hi, i am not sure if its work

but please give a try

try use Server.HtmlDecode, and Server.HtmlEncode

so from formview to database --> Server.HtmlEncode

from database to aspx --> Server.HtmlDecode

hope it does help

|||Thanks for answering! But where exactly would I have to put this?|||

its depending in your code.

let said you are trying to insert TextBox1.Text into database,

then the string insert into database will be Server.HtmlDecode(TextBox1.Text)

when you get string out from database and ready to show in the aspx page

you use Sever.HtmlEncode(stringFromDatabase)

|||Hm, ok, but I'm using a FormView ... It saves the text automatically. I didn't need to write code. And I supposed that the FormView would automatically handle the text correctly. Hm.|||

Hi,

Unforturnately, it will not handle the HTML encode. The only way to do this is call HTML encode manually using code.

No comments:

Post a Comment