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 += " ";
lblList += rowTitle["title"] + "<br />";
}
}
}
//Tony
|