views:

284

answers:

2

Hi, I am writing some XML data to the stringwriter. I want to pass the values in the stringwriter to the database but when I convert it to a string like

StringWriter.GetStringBuilder().ToString() it is converting all the " (double quotes) to \"

So when I pass that to database as parameter and when I try to read the data using openXML it's throwing an error.

Is there any work around for this ?

I am using ASP.NET 2.0
SQl server 2005

thanks!

+3  A: 

I strongly suspect that you're looking at the debugger. That will show the escaped form, but the quotes won't actually be in the string if they shouldn't be.

I suggest you log the string somehow - then you'll see the real data, and my guess is that it won't contain the backslashes - assuming you haven't written any backslashes to the StringWriter to start with. How are you writing the data to the StringWriter? Is it possible that your problems are further upstream? (If you're writing the XML manually, I'd strongly recommend that you use an XML API instead. It's much less error-prone.)

What error are you getting when trying to read the XML back? What does it look like in the database?

I can pretty much guarantee that the problem won't be in StringWriter or StringBuilder - they don't perform any escaping.

On another note, is there any reason why you're calling GetStringBuilder().ToString() instead of just ToString()?

Jon Skeet
Yes, correct thanks for the help.
Jebli
A: 

Jon Skeet gave me the right answer. Thanks.

Jebli