PC Review


Reply
Thread Tools Rate Thread

about C# and ado.net and relations

 
 
Tony
Guest
Posts: n/a
 
      8th Dec 2011
Hello!

The code below is from a book that I read.

I have three database tables called Authors, TitleAuthor and Titles. These
are from the Pubs database.
The relation these have is one to many beween Authors and TitleAuthor and
one to many between Titles and TitleAuthor .
The TitleAuthor is a relationtable between the Authors and the Titles

I have loaded the three tables into a dataset called dsPubs.

In this code I take the row in the Authors table and look op the
corresponding rows in the TitleAuthor by using the
GetChildRows because it could be many children rows and then I take the
corresponding row in the Title table by
using the GetParentRows.

Now to my question what is the point to use GetParentRows because there
could only exist one Title for
each TitleAuthor ?

It would be clearer to use GetParentRow instead of GetParentRows.


foreach(DataRow rowAuthor in dsPubs.Tables["Authors"].Rows)
{
lblList.Text += "<br /><b>" + rowAuthor["au_fname"];
lblList.Text += " " + rowAuthor["au_lname"] + "</b><br />";

foreach(DataRow rowTitleAuthor in
rowAuthor.GetChildRows(Authors_TitleAuthor))
{
foreach(DataRow rowTitle in
rowTitleAuthor.GetParentRows(Titles_TitleAuthor))
{
lblList += "&nbsp;&nbsp;";
lblList += rowTitle["title"] + "<br />";
}
}
}

//Tony

 
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



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:49 PM.