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 SqlDataAdapterDim sqladap2 As SqlDataAdapterDim 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 DataColumnDim childCol As DataColumn
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
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"))
What is the datarealation in ado.net and it's usage