A sample code to Create a relationship between two tables

A sample code to Create a relationship between two tables? A Datarelation represents a relationship between parent and child Datatable. ? The demonstration uses the GetChildRows to return the datarow of child objects for every child datarelation in datatable.[bold]Step 1: main.aspx[/bold][code]Label[/code][bold]Step 2: main.aspx.vb [/bold ...

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 15
June 01, 2003
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement
A sample code to Create a relationship between two tables? A Datarelation represents a relationship between parent and child Datatable. ? The demonstration uses the GetChildRows to return the datarow of child objects for every child datarelation in datatable.[bold]Step 1: main.aspx[/bold]


<asp:Label id="Label1" style"Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server">Label</asp:Label>

[bold]Step 2: main.aspx.vb [/bold]


Dim myconnection As SqlConnection

Dim myda 
As SqlDataAdapter

Dim ds 
As DataSet

Dim mydr 
As DataRelation

Try

myconnection = New SqlConnection("server=localhost;database=northwind;uid=sa;password=;")

myda = New SqlDataAdapter("Select * from Orders"myconnection)

ds = New DataSet()

myda.Fill(ds"Orders")

myda.SelectCommand.CommandText "Select * from [Order Details]"

myda.Fill(ds"OrdersDet")

mydr = New DataRelation("OrderRelation"ds.Tables(0).Columns("Orderid"), ds.Tables(1).Columns("Orderid"))

ds.Relations.Add(mydr)

Dim dr1 As DataRow

Dim dr2 
As DataRow

Dim strval 
As String

For Each dr1 In ds.Tables(0).Rows

       strval 
strval "<b>" dr1("Orderid") & "</b>
----------------
"

       
For Each dr2 In dr1.GetChildRows(mydr)

         
strval strval "Productid: " dr2("Productid") & " UnitPrice : " dr2("UnitPrice") & "

"

       
Next

Next

Label1
.Text = (strval)

Catch 
ex As Exception

        Response
.Write(ex.Message)

End Try

blog comments powered by Disqus
ASP.NET CODE ARTICLES

- How to Use the ListBox Control in ASP.NET 2.0
- How to Load XML Documents in ASP.NET 2.0
- DataGrid Code
- ASP.NET Guestbook
- User Controls and Client Side Scripting
- ASP.NET Programming with Microsoft's AS...
- ASP.NET Basics (part 3): Hard Choices
- ASP.NET Basics (part 2): Not My Type
- ASP.NET Basics (part 1): Nothing But .Net
- Directory Tree Browser
- How to get the confirmation of Yes/No from a...
- Complete example using custom errors and wri...
- Paging Certain # records per page .NET style
- General Methods of formatting and Subtractin...
- .NET LinkButton web control

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials