How to pull back one field from a child into parent

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

I have 2 datasets, Parent and Child, with a datarelation between the
2. Each Parent can have 1-n Childs. The Child table has a boolean
field called "FavoriteChild" of which only one of the related Childs
per Parent has the value set to true. How would I display the Name
field of the favorite child in each Parent record. Thanks.
 
I know of two ways which if combined would accomplish this in a nicer way,
but I just can't figure out how yet.
1)
DataRow[] allChildren = parentRow.GetChildRows(relationObject);
foreach(DataRow child in allChildren)
if((bool)child["FavoriteChild"])
return child["Name"];
2)
DataRow favoriteChild = childTable.Select("childFKColumn =
"+parentRow.<pkColumn>+ " AND FavoriteChild = 1");

substitute childFKColumn and pkColumn for the appropriate column names
also, not sure about using 1 for the boolean comparison. I think the filter
goes pretty much like a SQL Where clause.

It seems to me like there should be a way to use the relationship like in
1), then do a select from the smaller result set, but I haven't figured that
out yet.
 
Back
Top