views:

483

answers:

4

I have two tables in a DataSet where the ID field on each is the same. I have a Relation between the two tables. How do I, in C# code, pull the info from Table2 that relates to the info on Table1?

I have tried using a new DataRow and assigning it by using GetChildRow, but for some reason I cannot seem to make it work.

Also, I understand this question may not be that informative, let me know and I will try to provide more clarification.

+1  A: 
Jacob Proffitt
I am using a strongly-typed DataSet. Table1 is the parent, and I am trying to pull a column from Table2 of GroupName. Let me know if you need more clarifing comments, I know I asked a pretty vauge question.
Matt
+1  A: 

In a strongly-typed DataSet, each DataRow object will have specific methods or properties for each relationship. If you have a parent DataRow and want to navigate to children in Table2, it will be a pluralized method (i.e. "row.GetTable2Rows()"). If you have a child and want to navigate to the parent, it will be a singular property ("row.Table2Row").

Jacob Proffitt
So I now have this code: currentDataSet.GroupAttendingEventTable[groupAttendingEventCounter].GetGroupTableRows();How do I get info out of that code? I am trying to get the GroupName field out of the GroupTable. Sorry I am asking so many questions, I wish I knew more.
Matt
A: 

So here is what I did. Let me know if this is best if or there is something faster. I created a new table that is an exact replica of Table 2 and wrote this code:

currentDataSet.GroupTableOneRow.Clear();
currentDataSet.GroupAttendingEventTable[groupAttendingEventCounter].GetGroupTableRows().CopyToDataTable(currentDataSet.GroupTableOneRow, LoadOption.OverwriteChanges);

Then I can call the one table at record zero and get the name I need. It works, but is there a more efficent way?

Matt
A: 

A comment wasn't long enough for this response so I'll make it another answer:

There's no need to use a new table. Just use an array of row objects and go from there. Say your DataSet namespace is "EventData" and I'll break it down a bit so it isn't all on one line.

// The parent row
EventData.GroupAttendingEventRow groupAttendingEvent = currentDataSet.GroupAttendingEventTable[groupAttendingEventCounter];
// an array of children rows
EventData.GroupTableRow[] eventGroup = groupAttendingEvent.GetGroupTableRows();

Then you can act on the "eventGroup" array as you would like including getting at the first element with eventGroup[0].

Jacob Proffitt