Click here to Skip to main content
15,913,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all
I am using VB.NET, and I have data in a datatable. I want to pass it as a parameter to stored procedure in but in XML FORMAT. How can I pass it from datatable or dataset?
Posted

1 solution

Either create custom format which you will then create from the datatable (or dataset) or use datasets getXML method and pass that to the database.

I recommend using your own. It will be a) smaller b) easier to maintain (does not depend on eventual MS changes) and c) easier to parse (due to being your own).

Classes you need for such transformations are XmlNode, XmlDocument and XmlAttribute

I used the following format:
XML
<customers>
    <customer id="int" name="string" maxlimit="float" address="string" />
    <customer id="int" name="string" maxlimit="float" address="string" />
    <customer id="int" name="string" maxlimit="float" address="string" />
</customers>


Where attributes in the node are columns, nodes are rows and outer document node is table.

Also, due to way SQL uses XML, I didn't put any potential subnodes under customer (lets say you have more then one address - you might be tempted to do this
XML
<customer id="3" name="st">
    <address street="ul" />
    <address street="ul2" />
</customer>

DON'T! Instead, set another node <adresses> or something where you'll put all addresses from the customers and use PK/FK relationship to access them. Trust me, it saves time :)

If this helps please take time to accept the solution. Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900