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!
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
StringWriterto start with. How are you writing the data to theStringWriter? 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
StringWriterorStringBuilder– they don’t perform any escaping.On another note, is there any reason why you’re calling
GetStringBuilder().ToString()instead of justToString()?