Data Set and Data View objects in ADO.NET



DataSet Structure

A DataSet object falls in disconnected components series. You can use it with or without data providers. The DataSet consists of a collection of tables, rows, columns and relationships. Figure 1 illustrates these relationships specifically that the DataSet contains a collection of DataTables and the DataTable contains a collection of DataRows, DataRelations, and DataColumns. A DataTable maps to a table in the database. The previous DataSet contains a DataTable that maps to the Orders table because you filled it with a SELECT query executed on the Order table.

Figure-3.10.gif

Figure 1: The relationship between classes in a dataset

Well, now you see how you can look at your tables, but you still really haven't seen any hard data yet. The data in a DataSet is contained in the DataRow. A DataTable in the DataSet consists of a collection of DataRow. Each DataRow can be accessed via an index or the column name. As you can see from figure 1, a data set has a one-to-many relationship with DataTable. That means a DataSet can have one or more than one DataTable objects. Similarly, a DataTable can have one or more than one DataRelation, DataRow, and DataColumn objects.

DataSets in DataViews

Another thing you can do with the contents of your DataSet is sort and filter them using DataViews. You can have multiple Views of a dataset. A DataView is a view of your data created according to certain criteria. Each DataView has a one-to-one mapping to a DataTable in a DataSet. For example, say you have three tables in a dataset: table 1, table2, and table3. Using three different data tables and data views, you can represent this dataset in three different views. Using sort and filters, you can even sort and filter the data based on some criteria. Figure 2 shows three different views of a dataset in the form of three different data views.

Figure-3.11.gif

Figure 2: The relationship between Data Set and Data View objects

A dataview can directly attach to data-bound controls such as a DataGrid, DataList, or a Combo box.

Conclusion

Hope this article would have helped you in understanding Data Set and Data View objects. See my other articles on the website on ADO.NET.

Up Next
    Ebook Download
    View all
    Learn
    View all