JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

The DataRelation Class

DataRelation objects relate two data table objects to each other through the use of DataColumn objects. Datasets are just simple data repositories, and when you load them, they don't know anything about the relations between tables in a relational database (see "What Are Databases?" in Chapter 20). To make those relations explicit, you have to use DataRelation objects.

For example, in Chapter 21, the ParentChildData example used the publishers and titles tables in the pubs database, and related them through the pub_id key in a master/child relationship. The code displayed the publishers.pub_name field in the combo box you see in Figure 21.12 (the "master" part), and when the user selected a publisher, the program displayed all that publisher's books in the datagrid below (the "detail" part). We were able to create a data relation object in that example visually in Visual Basic as we edited the XML schema for the dataset in the example. In this chapter, we'll see how to get the same result by creating a DataRelation object in code. See "Creating a Data Relation Object in Code" in the Immediate Solutions for all the details.


You can access all the DataRelation objects in a dataset with the dataset's Relations property, as well as the ChildRelations and ParentRelations properties of a DataTable object.

And that's it—now it's time to get to the details in this chapter, in the Immediate Solutions section, and work with data objects in code.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor