Groups | Blog | Home
all groups > dotnet xml > march 2006 >

dotnet xml : wat is the best way to pass xml into Stored Procedure



SwatSoftwareDev
3/24/2006 12:00:00 AM
Hi All,

I want to use XML technologies with SQL Server 2000 for sending master
details data from Application to SQL Server. I'm using xmldocument class for
writing data in the form of attribute centric elements. First I write data
into xmldocument (using appendchild, setattributes methods), and then I use
outerxml property to get the xml in a string variable to pass it to stored
procedure as input parameter, where I use openxml to insert this data into
corresponding tables. But I face problem after writing xmldocument in C#
(but not in VB.NET). When I see the value of string variable in Command
Window it contains attributes attached with / before quotes (") like
<Customer ID=/"ALFKI/" City =/"NY/" />
What can be done to solve this problem?
I also want to know from experienced programmers that, is this the best way
to use XML for sending data to Database ? What way should I choose, if this
is not the best way?

Regards
Swat

fundamol NO[at]SPAM hotmail.com
3/31/2006 10:37:34 AM
Can you post some sample code? Its hard to understand how exactly you
load the XML into the SQL db.
Cerebrus
3/31/2006 2:08:25 PM
Hi Swat,

This is obviously an issue concerning familiarity with C#. I'm not that
experienced, but I think that what you're doing is the right way.

[quoted text, click to view]

Firstly, are you sure that the string you see in the command window is
:

<Customer ID=/"ALFKI/" City =/"NY/" />

and not :

<Customer ID=\"ALFKI\" City =\"NY\" /> //Note the difference is
back-slashes and forward-slashes.

I believe it would be the latter case, since the backslash is what C#
uses to escape double quotes and other special characters within
strings.

Now we can move on to the implication of those back-slashes on your
stored procedure. The answer is that there is no implication, and if
your coding is done right, those back-slashes won't cause any problem.

If you don't believe me, just try executing this line : (Debug mode)
///
Console.WriteLine("<Customer ID=\"ALFKI\" City =\"NY\" />");
\\\

The output (might) surprise you. The compiler treats it that way, but
doesn't necessarily output it that way too.

Regards,

Cerebrus.
AddThis Social Bookmark Button