ChildRelations

J

Jim Heavey

Hello, I have never used the childRelations and I was looking for an
opportunity to use this.

If I have two tables, One Called "state" which has a list of valid state
codes. I have another table which has Orders. I built a "foreign key"
relationship with between "State" and "Orders", with State being the parent
table.

Have I now done what I need to do to utilize the ChildRelationships or do I
need to set something else up? The online help show the following example:

DataRow[] childRows;
foreach(DataRelation myRelation in myTable.ChildRelations)
{
foreach(DataRow myRow in myTable.Rows)
{
PrintRowValues( new DataRow[] {myRow}, "Parent Row" );
childRows = myRow.GetChildRows(myRelation);
// Print values of rows.
PrintRowValues( childRows, "child rows" );
}
}

The thing which confuses me about this example is if my "parent table", in
my case "State" has many child related tables, such as "orders", "returns",
will this example bring back child rows of both order and returns? How
would you limit the relationships to a single table?

Likewise, Maybe it is not applicable, but could my "parent" table have more
then one "parent" relationship, say for Example, my "State" table has
"State Code Abbreviation" as the primary key and "State Name" as a unique
index. Some "child tables" have "State Code Abbreviation" and others have
"StateName" -how can you distinguish between these relationship in the
example?

Thanks in advance for your assistance!!!
 
M

Miha Markic

The thing which confuses me about this example is if my "parent table", in
my case "State" has many child related tables, such as "orders", "returns",
will this example bring back child rows of both order and returns? How
would you limit the relationships to a single table?

Each relation has exactly one parent and one child table.
So
childRows = myRow.GetChildRows(myRelation);
will give you child rows only for specified relation thus one child table.
Likewise, Maybe it is not applicable, but could my "parent" table have more
then one "parent" relationship, say for Example, my "State" table has
"State Code Abbreviation" as the primary key and "State Name" as a unique
index. Some "child tables" have "State Code Abbreviation" and others have
"StateName" -how can you distinguish between these relationship in the
example?

Yes, sure.
The same method as above.
parentRow = myRow.GetParentRow(myRelation);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top