Sort an XML document using DataView

G

Guest

Hi,

I am tring to use DataView Sort ability to sort an XML document, here are my
code snippet:

ds1.ReadXml("c:\temp\catalog1.xml")
ds1.Tables(0).DefaultView.Sort = "ProdName"
ds1.WriteXml("c:\temp\catalog2.xml")

Does not work at all, can someone help?

TIA
 
S

Scott Allen

The Sort property only applies if you look at the table through a
DataView (the DefaultView in this case). Since a DataView doesn't have
a WriteXml method, you'd have to hand craft the code to write the XML
out in specific order (perhaps by looping through the records as
sorted by DefaultView).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top