Welcome to Dream.In.Code
Become an Expert!

Join 150,068 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,801 people online right now. Registration is fast and FREE... Join Now!




Help with DataRelation in dataset

 
Reply to this topicStart new topic

Help with DataRelation in dataset, how to get my rows out of second table

minus4
10 Jun, 2008 - 08:15 AM
Post #1

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 3

hi i have a dataset of 2 tables.

table 1 holds the product info

table 2 holds the sizes available for that product as multiple options.

products is my dataset


CODE

Dim relation As DataRelation = New System.Data.DataRelation("productSizes", products.Tables(0).Columns("productID"), products.Tables(1).Columns("productID"))
        products.Relations.Add(relation)

column productSizes is the column in table 2 i want to loop through:

Dim mysizes As String = "sizes: "

            For Each DataRow In products.Tables(0).Rows(i).GetChildRows("productSizes")
                mysizes = ??????????????????????
            Next


what do you put in the question marks ?????????????


thanks

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Help With DataRelation In Dataset
10 Jun, 2008 - 10:07 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Notice how I changed the ForEach loop to return a collection of rows. You said table 2, so you need to change Table property from 0 to 1 to reflect this in the loop and access the second table.

CODE

For Each dr As DataRow In products.Tables(1).Rows
    mysizes = dr("productSizes").ToString()
Next

User is offlineProfile CardPM
+Quote Post

minus4
RE: Help With DataRelation In Dataset
11 Jun, 2008 - 12:11 AM
Post #3

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 3

hi thanks, that would just loop through table 2 and not actuall loop through the datarelation from table 2

i used the same code but put

CODE


Dim relation As DataRelation = New System.Data.DataRelation("productSizes", products.Tables(0).Columns("productID"), products.Tables(1).Columns("productID"))
        products.Relations.Add(relation)

For i = 0 To products.Tables(0).Rows.Count - 1

Dim mysizes As String = "sizes available: "

            For Each DataRow In products.Tables(0).Rows(i).GetChildRows("productSizes")
                mysizes = mysizes & "<br />" & DataRow("sizename").ToString
            Next

Next



but many thanks for your response



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 10:53PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month