|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sorting a Dataset tableHi,
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. -- Show quoteMiha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Jeronimo Bertran" <jeronimo.bertran@newsgroup.nospam> wrote in message news:Xns9797E4841D812publicjbbertrancom@207.46.248.16... > 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 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 Jeronimo,
You can go through the defaultview and than get from every datarowview that you get the drv.row.getchildrows collection. http://msdn2.microsoft.com/en-us/library/system.data.datarow.getchildrows.aspx I hope this helps, Cor Show quote "Jeronimo Bertran" <jeronimo.bertran@newsgroup.nospam> schreef in bericht news:Xns9798853F24F7publicjbbertrancom@207.46.248.16... > 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). -- Show quoteMiha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Jeronimo Bertran" <jeronimo.bertran@newsgroup.nospam> wrote in message news:Xns9798853F24F7publicjbbertrancom@207.46.248.16... > 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 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 Show quote "Jeronimo Bertran" <jeronimo.bertran@newsgroup.nospam> schreef in bericht news:Xns9797E4841D812publicjbbertrancom@207.46.248.16... > 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 MyDataTable.DefaultView.Sort="Firstname ASC"
Will sort the DefaultView in ascending order Using the Firstname column ( Or whatever column you have in there ). HTH Show quote "Jeronimo Bertran" <jeronimo.bertran@newsgroup.nospam> wrote in message news:Xns9797E4841D812publicjbbertrancom@207.46.248.16... > 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 |
|||||||||||||||||||||||