473,320 Members | 2,164 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,320 software developers and data experts.

How select from 2 ADO.NET DataTables?

Let's say I have 2 ADO.NET DataTables (tblAuthor and tblBook) within an
ADO.NET DataSet (dstPublish).

tblAuthor has DataColumns AuthorID and AuthorName, tblBook has DataColumns
BookID, BookTitle, AuthorID (assume a book can be written by only one
author).

tblAuthor

---------

1 Ayn

2 Jim

3 Sue

tblBook

-------

10 Fountainhead 1

11 Atlas Shrugged 1

12 Moby Dick 2

I want to create a list of all books with their associated author name.

FountainHead Ayn

Atlas Shrugged Ayn

Moby Dick

This is a breeze in SQL for me, but I'm not sure how to go about using
ADO.NET DataTables. Do I need a DataRelation, or is it just a matter of
having a for loop within a for loop, or is it something else?

Thanks,

Ron


Mar 10 '06 #1
1 1286
>Do I need a DataRelation, or is it just a matter of
having a for loop within a for loop

You can create a DataRelation. The DataRow has methods for navigation
along the data relation like GetParentRows, GetParentRow, GetChildRows,
etc. Something like this:

dataSet.Relations.Add(tblAuthor.Columns["ID"],
tblBooks.Columns["AuthorID"]);
Change the column names appropriately.

foreach (book row in tblBookx)
{
Row authorRow = row.GetParentRow();
}

You still have to loop, but it simplifies parent looking-up by removing
the inner loop.

Thi

Mar 10 '06 #2

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

Similar topics

2
by: Jade | last post by:
Hi, I just wanted to ask a quick question regarding datasets. I am creating 3 tables using a dataadapter. what i want to know is that is the relationship created between these datatables...
1
by: Harry V | last post by:
I'm wondering if there is a limit of a single select, delete and insert statement (command) to each dataadapter? On a form, I have a dataconnection that is shared by 3 dataadapters, one for each of...
2
by: Z D | last post by:
Hello, I'm currently using Remoting (HTTP/Binary) to remote a simple object. Everything is working fine except for one function that returns an arraylist of datatables. When I call this...
3
by: cj | last post by:
I've used datatables and datasets before. Datasets being able to hold more than one table and datatables being only one table. My mind keeps coming up with recordsets. I can't remember how they...
1
by: Ronald S. Cook | last post by:
Let's say I have 2 ADO.NET DataTables (tblAuthor and tblBook) within an ADO.NET DataSet (dstPublish). tblAuthor has DataColumns AuthorID and AuthorName, tblBook has DataColumns BookID,...
3
by: bbdobuddy | last post by:
Hi, I have two datatables that I want to left outer join and then do some queries on but I having a hard time figuring out how to join the datatables together. One of the datatables comes from...
5
by: njb35 | last post by:
Hi all I'm beginning my foray from VBA into VB 2005 Express, and enjoying some of the efficiencies it provides! I'm stuck with some dataset handling however that I _think_ can be automated but...
3
by: =?Utf-8?B?UmljaCBIdXRjaGlucw==?= | last post by:
I'm not really sure how to ask this question because I'm still getting my feet wet with data access and VB.NET, but here goes: To start off with, I'm using VB 2005 Express to connect to an Access...
2
by: riltim | last post by:
Hi, I have a situation where I need to take multiple DataTables and convert them to a single Datatable which would be simple if I didn't need to convert them into a matrix where like items will...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.