Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get this?
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00842497
Message ID:
00842530
Views:
14
Ahmad,

Here is some sample code from my ADO.NET session that shows how to iterate through the records. You use the GetChildRows to iterate through the child table:
Dim ds As New DataSet()

Dim strSQL As String = "SELECT Cust_ID, Order_Id, “ & _
	“Order_Date FROM Orders WHERE Year(Order_Date) > 1997"
Dim oda As New OleDbDataAdapter(strSQL, connStr)
oda.Fill(ds, "OrderInfo")

strSQL = "SELECT CustomerID FROM Customers “  & _
	“ORDER BY CustomerID"
Dim sda As New SqlDataAdapter(strSQL, connStr)
sda.Fill(ds, "CustomerInfo")

Dim dc1 As DataColumn = _
	ds.Tables("CustomerInfo").Columns("CustomerId")
Dim dc2 As DataColumn = _
	ds.Tables("OrderInfo").Columns("Cust_Id")

Dim dr As New DataRelation("CustomersToOrders", dc1, dc2)
ds.Relations.Add(dr)

Dim drCustomer As DataRow
Dim drOrder As DataRow

For Each drCustomer In ds.Tables("CustomerInfo").Rows
	lstDemo.Items.Add("Customer: " & _
	drCustomer("CustomerId").ToString())
	' Iterate through related rows.
	For Each drOrder In drCustomer.GetChildRows(dr)
		lstDemo.Items.Add( _
			String.Format("   Order {0} placed on {1:d}", _
			drOrder("Order_ID"), drOrder("Order_Date")))
	Next drOrder
Next drCustomer
>Hi All,
>
>I have 2 tables having a datarelation between them
>the master table is "Member" an second table is "Subs", the relation is created as follow:
>
>myDS.Relations.Add("MemSub", myDS.Tables("Member").Columns("MemberID"), myDS.Tables("Subs").Columns("MemberID"))
>
>how to read the feilds from the datarelation, or how to create the datarow from the datarelation "MemSubs" to read the "subs" colums ?
>
>thanks for the help
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform