What is the datarealation in ado.net and it's usage

Showing Answers 1 - 4 of 4 Answers

Anup

  • Jan 23rd, 2006
 

In the Data Set we can store many tables.Eg. If we have two tables

Orders and Order Details in the dataset then we can maintain a relation

between the two tables using the Data Relation class by giving the

columns to be linked.

  Was this answer useful?  Yes

anup2006

  • Jan 24th, 2006
 

In Ado.Net DataSet is an in memory representation of data.We can store many tables inside it.

for eg.If there are two tables Order and Order Details in the DataSet and having a common column, orderid

then we can link the two tables and maintain a relation with the orderid using the DataRelation class and we can fetch the related datas

  Was this answer useful?  Yes

anup2006

  • Jan 24th, 2006
 

DataRelation is a class which is used to maintain a parent-child relationship between two tables in a DataSet.The following example will make more clear to u

Open a Windows Application and place a Datagrid in it.

Then write the code in the Form load event

Dim sqlConnect As New SqlConnection('Put your Connection string here")

I am using the Nothwind Database

Dim sqladap1 As SqlDataAdapter

Dim sqladap2 As SqlDataAdapter

Dim ds As New DataSet

'Filling the dataset wth two tables

sqladap1 = New SqlDataAdapter("Select * from orders where orderid < 10252", sqlConnect)

sqladap2 = New SqlDataAdapter("Select * from orderdetails where orderid < 10252", sqlConnect)

sqladap1.Fill(ds, "Orders")

sqladap2.Fill(ds, "Orderdetails")

Dim parentCol As DataColumn

Dim childCol As DataColumn

 

parentCol = ds.Tables("Orders").Columns("OrderID")

'Also u can write

parentCol = ds.Tables(0).Columns("OrderID")

childCol = ds.Tables("Orderdetails").Columns("OrderID")

' Create DataRelation.

Dim relCustOrder As DataRelation

relCustOrder = New DataRelation("CustomersOrders", parentCol, childCol)

' Add the relation to the DataSet.

ds.Relations.Add(relCustOrder)

DataGrid1.DataSource = ds

After executing u can see for each orderid the relation

Customersorders is linked with each row

With Rgs

Anup

  Was this answer useful?  Yes

Basalingamma

  • Mar 16th, 2006
 

DataRelation is an object through which two tables of a Dataset can be related.

Ex:In VB declaration is

Dim data_relation As New DataRelation("<relation name>", egptDataset.Tables("datatable1").Columns("<primary key column>"), egptDataset.Tables("datatable2").Columns("Foreigh key column"))

 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.