Sorting a Dataset table

  • Thread starter Thread starter Jeronimo Bertran
  • Start date Start date
J

Jeronimo Bertran

Hi,

I need to export the contents of a DataTable in a Dataset to a text file in
a particual row order. I guess I need to use the DefaultDavaView but I
think I am doing something wrong since traversing the rows in the table
doesn't show them in the correct order.

Thanks

Jeronimo Bertran
 
DataView sorting affects just dataview.+ (it doesn't actually sort
DataTable).
You should iterate over DataView rows instead.
 
Jeronimo,

You are right, but we cannot see what you do wrong if we don't see the code
that you use to go trough that defaultview.

Cor
 
MyDataTable.DefaultView.Sort="Firstname ASC"

Will sort the DefaultView in ascending order Using the Firstname column ( Or
whatever column you have in there ).

HTH
 
Sorry, here is a detailed description of the problem.


My dataset hast tow tables which are used as master/detail. Assume table1
is Customers and table2 is Orders. I need to export all of the orders for
a given customers in a particular order.


Thr relationship is defined as

this.relationFK_Orders_Customers = new System.Data.DataRelation
("FK_Orders_Customers", new System.Data.DataColumn[] {
this.tableCustomers.CustomerIDColumn}, new
System.Data.DataColumn[] {
this.tableOrders.CustomerIDColumn}, false);



Now, in order to export the records for a given customer row I am doing the
following:

// need to sort the orders
foreach (dataset.OrdersRow order in customerRow.GetChildRows
("FK_Orders_Customers"))
{

// Export order
}


I don't see how I can use the dataView here.

Thanks

Jeronimo Bertran
 
Hi Jeronimo,

Instead of using GetChildRows, use new DataView over child table with
relation conditions (manually filtering rows).
 
Back
Top