Home All Groups Group Topic Archive Search About
Author
1 Apr 2006 6:27 AM
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

Author
1 Apr 2006 8:47 AM
Miha Markic [MVP C#]
DataView sorting affects just dataview.+ (it doesn't actually sort
DataTable).
You should iterate over DataView rows instead.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

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
Author
1 Apr 2006 8:33 PM
Jeronimo Bertran
Thanks,
Author
1 Apr 2006 9:05 PM
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
Author
2 Apr 2006 7:27 AM
Cor Ligthert [MVP]
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
Author
2 Apr 2006 11:57 AM
Miha Markic [MVP C#]
Hi Jeronimo,

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

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"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
Author
4 Apr 2006 1:08 AM
Jeronimo Bertran
Ok, that's what I did.

Thanks
Author
1 Apr 2006 12:02 PM
Cor Ligthert [MVP]
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
Author
1 Apr 2006 12:50 PM
Terry Burns
MyDataTable.DefaultView.Sort="Firstname ASC"

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

HTH


--
Terry Burns
http://TrainingOn.net
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

AddThis Social Bookmark Button