DataTable Versus DataView "-->
only for RuBoard |
On the outside, a DataTable and DataView are identical in structure. They are both made up of columns and rows. The difference between the two objects is how they are derived. A DataView is derived from a DataTable and is a customized view of that DataTable . At a high-level, a DataTable can be compared to a table from a database and a DataView can be compared to a SQL View.
One or more DataViews can be created from a single DataTable and each one of the DataViews can have rows edited, updated, deleted, filtered, and searched. As previously mentioned, both the DataView and DataTable are constructed of columns and rows and in this chapter those are the two pieces we will be concentrating on. Both the DataTable and the DataView are constructed with a DataRowCollection and DataColumnCollection . The diffence is when working with a DataView you are working with a "view" of this data and in order to manipulate its data (rows) you will use a DataRowView rather than the DataRow as you do with the DataTable . In the following sections, I'll be giving you a high-level view of the DataRow , DataRowView , and DataColumn objects.
A DataTable contains a collection of rows called the DataRowCollection ; this collection holds all the actual data (rows) in the table. You can think of the DataRowCollection as rows in a database table.
Just as a DataView is a customized view of a DataTable , a DataRowView is a customized view of a DataRow , and as you will see in this chapter, changes to the data to either one of these objects can have a direct effect on the other. For instance, if you have two DataView objects derived from one DataTable and a row is deleted from one of them; the second DataView and the DataTable also will reflect this row deletion unless specific measures are taken ”which we will cover later in the chapter. Even though the the DataView and DataRowView are derived, and to a degree, dependent on the DataTable and DataRows from which they were derived, they have many of their own properties and methods available to manipulate their data (as you will see in this chapter)
The DataColumn object is identical in both the DataTable and DataView . The DataColumn is the foundation of a table; it, among other things, describes the schema for the table including the columns data type, whether it allows null values, whether it's read only, or whether the column should be auto-incremented.
You can construct the DataColumn to mimic a schema from your database so that you can merge its data directly into a database without having to format or change data types. In the next section on DataTable s, you'll see code demonstrating how you can construct a DataTable from scratch rather than populating it from data derived from a database. Beyond that, you will see some of the properties of the DataColumn that describe data contained in each column's rows.
only for RuBoard |