typed dataset and sort order on save

  • Thread starter Thread starter Donal McWeeney
  • Start date Start date
D

Donal McWeeney

Hi,

Is it possible to force a typed dataset to write out records with a
particular sort order on the WriteXml() method.

Thanks

Donal
 
On the second thought, you might create another typeddataset, transfer rows
in desired order (from original dataset) and then invoke WriteXml on this
target dataset.
 
Donal,

A dataset directly holds no records.
However datatables holds rows, do you mean one or more datatables?

A simple way for that is this is

\\\
DataView dv = new DataView(dt);
dv.Sort = "bla"; // sorts column bla
DataTable dtnew = dt.Clone();
foreach (DataRowView dvr in dv)
dtnew.ImportRow(dvr.Row);
dt.Clear();
dt = dtnew.Copy();
///

I hope this helps?

Cor
 
Donal:

You can traverse the XML document very easily using the XML namespace and
with XSLT - which you'd only have to write once - you can sort away any way
you'd like. Moreoever, like Miha mentions - a sort order on the save
probably isn't necessary - you can do the sorting whenever you deserialize
the dataset using the code that Cor showed you.
 
Just playing with a prototype at the moment which will be collecting lots of
data - If I need to manually edit the xml, having it stored in sorted format
will make it much easier...
 
XSLT is your friend ;-)

Since a DataSet is comprised of 0 or more tables - sorting is a bit dubious
here .... however with XSLT you can sort in any way you want and it's pretty
straightforward.
 
Back
Top