How to pull back one field from a child into parent

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.
 
B

Bill Mittenzwey

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.
 

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