DataRelation on Multible layers of DataRelations

G

Guest

I can relate two tables rather easily using the following code:
dsClub.Relations.Add("Section_Data",
dsClub.Tables["Section"].Columns["SectionID"],
dsClub.Tables["SData"].Columns["SectionID"]);

Which connects the "Section" table to the "SData" table rather easily using
the "SectionID" primary key. My question is:
I need to connect an "img_tbl" table to the "SData" table that is
constrained by the "Section" table so that the rows returned in the "SData"
table constrain the "img_tble"; ie, Parent/Child/Grandchild relationship.
The tables "SData" and "img_tbl" have their own Primary/Foreign key to
connect them together called "sdID" How do I set the the Grandchild
relationship between the two?
 
K

Karl Seguin

Sam:

can't you just add a 2nd relationship:

dsClub.Relations.Add("Data_Image", dsClub.Tables["SData"].Columns["sdID"],
dsClub.Tables["img_tbl"].Columns["sdID"]);

then when you have a row in Section, you can call
GetChildRows("Section_Data")

which will return all the Child rows...and then you can take one of those
and call GetChildRows("Data_Image") to return the grandchildren rows

Karl
 
G

Guest

Karl;

I did as you suggested but used a nested Repeater as follows:
<asp:Repeater ID="clubRep1" Runat="server">
<HeaderTemplate>
<table><tr><td>
</HeaderTemplate>
<ItemTemplate>
<asp:Repeater ID="clubRep2" DataSource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows("Section_Data")%>'
Runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# (DataBinder.Eval(Container.DataItem,
"[\"SectionDTitle\"]"))%></td>
</tr>
<tr>
<td>
<asp:Repeater DataSource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows("DataFK")%>'
Runat="server">
<ItemTemplate>
<img src='<%# "Sonar3/UploadImg/" +
DataBinder.Eval(Container.DataItem, "[\"ImgName\"]") +
DataBinder.Eval(Container.DataItem, "[\"imgType\"]")%>' />
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</td></tr></table>
</FooterTemplate>
</asp:Repeater>

I recieved an error as follows on the third repeater:

"Specified cast is not valid. "

Any Suggestions?

Karl Seguin said:
Sam:

can't you just add a 2nd relationship:

dsClub.Relations.Add("Data_Image", dsClub.Tables["SData"].Columns["sdID"],
dsClub.Tables["img_tbl"].Columns["sdID"]);

then when you have a row in Section, you can call
GetChildRows("Section_Data")

which will return all the Child rows...and then you can take one of those
and call GetChildRows("Data_Image") to return the grandchildren rows

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
I can relate two tables rather easily using the following code:
dsClub.Relations.Add("Section_Data",
dsClub.Tables["Section"].Columns["SectionID"],
dsClub.Tables["SData"].Columns["SectionID"]);

Which connects the "Section" table to the "SData" table rather easily using
the "SectionID" primary key. My question is:
I need to connect an "img_tbl" table to the "SData" table that is
constrained by the "Section" table so that the rows returned in the "SData"
table constrain the "img_tble"; ie, Parent/Child/Grandchild relationship.
The tables "SData" and "img_tbl" have their own Primary/Foreign key to
connect them together called "sdID" How do I set the the Grandchild
relationship between the two?
 
K

Karl Seguin

ooops...try using CreateChildView("XXXX") instead of GetChildRows this
will make your datasouce a DataView, making your individual records a
DataRowView GetChildRows makes your datasource an array of DataRows thus
making your invidual items DataRows (i think)...both would work though...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
Karl;

I did as you suggested but used a nested Repeater as follows:
<asp:Repeater ID="clubRep1" Runat="server">
<HeaderTemplate>
<table><tr><td>
</HeaderTemplate>
<ItemTemplate>
<asp:Repeater ID="clubRep2" DataSource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows("Section_Data")%>'
Runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# (DataBinder.Eval(Container.DataItem,
"[\"SectionDTitle\"]"))%></td>
</tr>
<tr>
<td>
<asp:Repeater DataSource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows("DataFK")%>'
Runat="server">
<ItemTemplate>
<img src='<%# "Sonar3/UploadImg/" +
DataBinder.Eval(Container.DataItem, "[\"ImgName\"]") +
DataBinder.Eval(Container.DataItem, "[\"imgType\"]")%>' />
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</td></tr></table>
</FooterTemplate>
</asp:Repeater>

I recieved an error as follows on the third repeater:

"Specified cast is not valid. "

Any Suggestions?

Karl Seguin said:
Sam:

can't you just add a 2nd relationship:

dsClub.Relations.Add("Data_Image", dsClub.Tables["SData"].Columns["sdID"],
dsClub.Tables["img_tbl"].Columns["sdID"]);

then when you have a row in Section, you can call
GetChildRows("Section_Data")

which will return all the Child rows...and then you can take one of those
and call GetChildRows("Data_Image") to return the grandchildren rows

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
I can relate two tables rather easily using the following code:
dsClub.Relations.Add("Section_Data",
dsClub.Tables["Section"].Columns["SectionID"],
dsClub.Tables["SData"].Columns["SectionID"]);

Which connects the "Section" table to the "SData" table rather easily using
the "SectionID" primary key. My question is:
I need to connect an "img_tbl" table to the "SData" table that is
constrained by the "Section" table so that the rows returned in the "SData"
table constrain the "img_tble"; ie, Parent/Child/Grandchild relationship.
The tables "SData" and "img_tbl" have their own Primary/Foreign key to
connect them together called "sdID" How do I set the the Grandchild
relationship between the two?
 

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

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top