473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Datatable based on two other datatables (inner join)

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

Nov 19 '05 #1
1 20519
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" <ka*****@comcast.net> wrote in message
news:Xf********************@comcast.com...
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


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: gro.asumsa | last post by:
I have two DataTables in a DataSet. I would like to create a third DataTable in the same DataSet that is a Join of the two original DataTables. The two tables are extracted from two different...
2
by: Ester | last post by:
I would like to accomplish the following task in WebForm.aspx I have a SQL SELECT query that INNER JOIN two tables (Device_Tbl and Detail_Tbl) which will return Device_BtnID Status Z_Index ...
3
by: Peter | last post by:
Hi, I have two datatables and I want to efficiently query the intersection of the two using the studentID. In my example code below, I want to print out Mary and Jane and their exam grades and I...
0
by: Gene Ariani | last post by:
I have one dataset that contains two DataTables: DataTable1: Customer_ID 1
1
by: cindy | last post by:
Get data into datatable, add to dataset dsSearch " Get data into datatable, add to dataset dsSearch Using In-Memory SQL Engine join the tables and select the filenames from the join, add to...
3
by: Prasun | last post by:
Hello: Is it possible to create a datatable that is an Inner Join of two existing datatables in a Dataset. If so, how do you do so? Thank You Prasun
1
by: Simon | last post by:
Hi all, I have the following query which I want to use to update a DataTable: "SELECT tblVmsResponse.IntDestZone,(tblVmsResponse.LngDestinationDiversionNum) as Diversionnumber," & "...
2
by: Marcel Hug | last post by:
Hi NG! With a Inner-Join SQL I get my datas in a DataSet. In the table are the column Entry and Version. Like this: Entry Version 1 1 1 2 1 ...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.