Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Inserting HTML, getting gibberish back?

Author  Topic 

JeTmAn81
Starting Member

11 Posts

Posted - 2008-09-25 : 15:08:21
Hi folks, I've got a program where snippets of HTML code are inserted into a SQL 2000 database and then pulled out to be put together into an HTML file. The assembled HTML pieces are actually being saved as a .doc so the user can open it in Microsoft Word and essentially get a Word document that is assembled on the fly according to various sections which are specified as needed for the document.

Anyway, I've got a problem where most of the document looks fine, but wherever there should be an apostrophe, in the finished document it's replaced by three ASCII characters, the last of which is the trademark symbol. So for some reason it just doesn't translate this correctly. The HTML is getting saved in the database in an ntext field, though it's being converted to a varchar before getting saved there. It seems to me like this is some kind of an issue involving encoding, possibly ASCII vs. Unicode, but I don't know how to resolve it.

When the HTML gets inserted into the database, it's done through an ASP.NET webpage which takes input from a textbox. When I copy and paste into the textbox from notepad, I notice that apostrophes show up but do not appear to be the exact same character as if I had just typed the apostrophe directly into the textbox. When I replace an apostrophe that I've pasted in by just typing the character, then it seems to display correctly after being pulled from the database.

This has been a very frustrating issue for me, so any help that could be given would be greatly appreciated.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-25 : 15:13:09
If you run a select statement that returns a row with the apostrophe, does it show up correctly in Query Analyzer? If so, then your issue is somewhere in your application which means that you should post your question on a forum that deals with your programming language (I'd suggest www.asp.net).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-25 : 15:39:30
There is a .net forum here
http://www.sqlteam.com/forums/forum.asp?FORUM_ID=17

What datatype are you using to store your data ?

I would advice that, you use htmlencode to encode your data, this would change the basic programming elements to html format, before its saved to the database and when retrieved it will reformat it back to html format. E.g.

In .net's c# you can use

string msg = HttpContext.Current.Server.UrlEncode(message);


Bear in mind, characters such as & + ( ) # ? etc

Have other functions in T-SQL, so they need to be encoded before they are saved.

Hope this helps

Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-25 : 15:40:22
Another way around it is to use richtext format
Go to Top of Page

JeTmAn81
Starting Member

11 Posts

Posted - 2008-09-25 : 15:54:09
Well, it looks like it pulls without any special characters in Query Analyzer, so I guess I'll need to try my luck on the ASP.NET forums. I did try the UrlEncoding method, wherein I encoded it before inserted it, then decoded it again after pulling it out of the database, but unfortnately that didn't work. I would like to try using a rich text format but I'm not sure if ASP.NET supports that natively. Actually, maybe the newer versions do, I'm still using Visual Studio .NET 2003 because 2008 runs pretty slowly on my machine and I skipped 2005. Thanks for the quick and helpful responses, everyone, I will take this to some .NET forums.
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-25 : 16:13:56
quote:
Originally posted by JeTmAn81

I would like to try using a rich text format but I'm not sure if ASP.NET supports that natively.



no rtf is not supported as yet

Am using VStudio 2008 and .net c# 3.5 NO problems
Go to Top of Page
   

- Advertisement -