PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

Datatable based on two other datatables (inner join)

 
 
Gene Ariani
Guest
Posts: n/a
 
      21st Aug 2003
I have one dataset that contains two DataTables:



DataTable1:

Customer_ID

1

2

3

4

5



the other DataTable2 returns

Customer_ID

4

5



If I would have treated this as regular queries and join them on Customer_ID
the resulting set would only contain:



Customer_ID

4

5



Is there a way to inner join the two DataTables to create a third DataTable
with the desired results. I have tried to user Relations.Add method with no
success.



Thanks



Gene





 
Reply With Quote
 
 
 
 
Prateek
Guest
Posts: n/a
 
      22nd Aug 2003
To work with a DataRelation and get joined rows, you will need to use the
GetChildRows method of DataRow and pass the DataRelation object. Below is a
code extract. There is no direct way to get the child rows.

------------------------------------
The following code example creates a DataRelation between the Customers
table and the Orders table of a DataSet and returns all the orders for each
customer.

Dim custOrderRel As DataRelation = custDS.Relations.Add("CustOrders", _
custDS.Tables("Customers").Columns("CustomerID"), _
custDS.Tables("Orders").Columns("CustomerID"))

Dim custRow As DataRow
Dim orderRow As DataRow

For Each custRow in custDS.Tables("Customers").Rows
Console.WriteLine(custRow("CustomerID"))
For Each orderRow in custRow.GetChildRows(custOrderRel)
Console.WriteLine(orderRow("OrderID"))
Next
Next
------------------------------------

You can however, create a separate command object, associate the join SQL
query with it and populate a third DataTable in the DataSet using this
command object.

-Prateek

"Gene Ariani" <(E-Mail Removed)> wrote in message
news:XfednaMPY5je1tiiU-(E-Mail Removed)...
I have one dataset that contains two DataTables:



DataTable1:

Customer_ID

1

2

3

4

5



the other DataTable2 returns

Customer_ID

4

5



If I would have treated this as regular queries and join them on Customer_ID
the resulting set would only contain:



Customer_ID

4

5



Is there a way to inner join the two DataTables to create a third DataTable
with the desired results. I have tried to user Relations.Add method with no
success.



Thanks



Gene






 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I join Datatables inside dataset to become a new datatable? =?Utf-8?B?aGFuZ2RlZQ==?= Microsoft VB .NET 1 21st Jul 2006 07:08 AM
DataTables and Inner Join Prasun Microsoft ADO .NET 5 17th May 2005 06:09 PM
One DataTable out of two DataTables =?Utf-8?B?TGFsaXQ=?= Microsoft ADO .NET 1 5th Nov 2004 07:04 PM
Datatable based on two other datatables (inner join) Gene Ariani Microsoft ASP .NET 0 21st Aug 2003 11:46 PM
Datatable based on two other datatables (inner join) Gene Ariani Microsoft Dot NET Framework 0 21st Aug 2003 11:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:17 PM.