Sorting dataset (C#)

  • Thread starter Thread starter Hushpappy
  • Start date Start date
H

Hushpappy

Hello,
I'm trying to sort a dataset,
for some reason, when i use the writeXml of the dataset obeject I don't
see any change.

i'm trying to put the view into a dataview and then sort it but
nothings happens.

please advise.
 
Hushpappy,

The DataView only sorts the data shown when you bind to it. As a
result, writing the data out to XML is not going to be affected, since that
is an operation on the DataSet, not the view.

What you will have to do is write the XML, and then transform it using
an XSLT transformation, writing the values in the order that you wish.

Hope this helps.
 
Hushpappy,
Just for clarity's sake, you don't "Sort" a DataSet - you sort the
DataTable(s) that it contains. When you set a DataView (such as the
DefaultView of a datatable) and set its sort property, you are performing the
sort on the DataView, not on the DataTable from which it was derived.

If you actually want to reorder the rows in the DataTable itself, you would
need to reconstruct a new DataTable and import the rows in the correct order.

Hope that helps.
Peter
 
Hi,

You never physically reorder the datatable , what you do is create a view of
that data, this view can be sorted using any criteria you want.

In theory you do not need the datatable sorted, if all your iterations
operation happen using a view you will have the datatable sorted as needed.

This gives you the opportunity of having the same table with more than one
sorting at the same time.

In the weird case that you really want to save the values in a particular
order, there are several ways of doing it. you could create a new datatable
with the same schema and copy all the rows in the correct order.
Notice that there is nothing in the docs that assure you than even so you
will have the rows in the expected order though.
 
Hushpappy said:
Hello,
I'm trying to sort a dataset,
for some reason, when i use the writeXml of the dataset obeject I don't
see any change.

i'm trying to put the view into a dataview and then sort it but
nothings happens.

please advise.

Hushpappy, if you are populating your dataset from the result of a SQL
query, why not use the "Order by" clause ?, just a thought ?
 

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

Back
Top