SIGN UP MEMBER LOGIN:    
Blog

Create a relationship between DataSet tables

Posted by Mukesh Kumar Blogs | ADO.NET in VB.NET Jun 23, 2011
Create a relationship between DataSet tables

Create a relationship between DataSet tables


The DataRelation class used to joins tables in DataSet. You can found DataRelation class within the System.Data namespace. Each relationship includes a parent and a child. Add two tables one for parent and another one for child to your DataSet to create a relationship between them. Then create a new DataRelation instance, passing its constructor the name of the new relationship, plus a reference to the linking columns in each table.

  Dim objDS As New DataSet()

            objDS.Tables.Add(Employee)

            objDS.Tables.Add(Department)

            Dim objRelation As New DataRelation("objRelation",

            Employee.Columns!EmpID, Department.Columns!EmpID)

            objDS.Relations.Add(objRelation)

 

In above example we are joining an Employee table with a Department table, linking the Employee.EmpID column as the parent with the related Department.EmpID column as the child.



share this blog :
post comment