DataRelations?

K

Kevin

Hi All

this is going to be a lengthy questions do please bear
with me....

I have a database that has three tables - Employees,
ShiftHeader,ShiftDetails

Now the employees table holds the ShiftID for the
ShiftHeader table, to determine which shif t the employee
belongs to, As for the ShiftHeader table it has the
ShiftID, and a bunch of other information relating the
the Shift as a whole. Now for the ShiftDetails, this
holds detailed info about the specific ShiftID So in
other words my relationships look like this :

Employee ShiftHeader
ShiftDetails
ShiftID (Many-------1) ShiftID (1----Many) ShiftID

(Sorry for the disgusting diagrams!)

But my problem is the following:

I have a Datarow that I have declared inside a foreach
loop that cycles through all the employees. This Datarow
is set to retrieve the Parentrow(ShiftID from
ShiftHeader) eg

foreach(DataRow drEmp in Dataset.Tables["Employees"].rows)
{
DataRow drShiftHeader
drShiftHeader = drEmp.GetParentRow(EmpShiftHeadRel);
//do dome work with the drShiftHeader

}

Now that goes well and I can cycle through the
drShiftHeader columns and Debug.Write the data, but I
cannot seem to get the Child rows of the drShiftHeader
DataRow eg

foreach(Datarow drEmp in Dataset.Tables["Employees"].rows)
{
DataRow drShiftHeader
DataRow[] drShiftDetails
drShiftHeader = drEmp.GetParentRow(EmpShiftHeadRel);
//do dome work with the drShiftHeader
drShiftDetails = drShiftHeader.GetChildRows
(ShiftHeadertoShiftDetailsRel);
//drShiftDetails.Length = 0!

}
Can anyone direct me what to do in order for me to
retrieve the child rows of the parent row I have just
gotten? What am I doing wrong here?

Thanks for nay help - it is much appreciated

Kevin
 
D

David

You did not give the code which build the relations. If I were you I will
first check that code make sure I put the columns at right sequence in the
constructor arguments. first column is parent and sencond column is child.

Hope this will help.
 
D

David

You did not give the code which build the relations. If I were you I will
first check that code make sure I put the columns at right sequence in the
constructor arguments. first column is parent and sencond column is child.

Hope this will help.
 
M

Marco Martin

Kevin,

You're going to have to establish a Datarelation.

pseudo-code:

DataRelation oRelation = new
DataRelation(strRelationName,dataset.parentTable.Parentcolumn,
dataset.childTable.ChildColumn);

dataset.Relations.Add(oRelation);

check the docs for exact systax, but this should get you started. Once this
is done, you should get results back when doing a row.getChildRows() method.

hth,

Marco
 

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