Difference between able, dataview, and Dataset

Source: Internet
Author: User

1. datatable

Datatable indicates a table of data in the memory. It exists independently in the memory and contains all the information of this table. Datatable can be a table read from the database through a connection. Once the data is read to the datatable, The datatable can be detached from the data source; it can also be a table created entirely by the program through code.

◆ Datacolumn

A table is a two-dimensional structure composed of rows and columns. The table structure is composed of a collection of datacolumn objects. A collection of datacolumn objects can be composed of datatable. the columns attribute can be obtained, and the schema of the table is determined by defining the data type of each column, similar to defining a table in a database. After the table structure is defined, datarow can be generated based on the structure. The datatable. newrow () method is used to generate a new row of the datatable structure.
A able is composed of datarow sets, which can be accessed by the datatable. Rows attribute.

Datatable can also use the expression of the expression attribute to create some columns through existing columns.

1. Create calculated Columns
For example, if you already have a table structure and the table has a collection of datacolumns with a column named unitprice, you can create a new datacolumn, set columnname, and then set the expression for this column, datacolumn. expression = "unitprice * 0.086". The value of this column is calculated from the column named unitprice. When creating an expression, use the columnname attribute to reference the column.

2. The second purpose is to create an aggregate column.
Aggregate columns are usually executed along the Link (for the description of the relationship, see the datarelation section below). If the order table is a subtable named detail, the two tables use order. orderid and detail. the two orderid columns establish a relationship. The datarelation object is named "order2detail". In the order table, an aggregate column can be created, the sum of the price of all items contained in each order in the detail table is calculated as follows: datacolumn. expression = "sum (Child (order2detail ). price) ", child (order2detail) indicates the child table that is connected through the order2detail relation, child (order2detail ). price indicates the price column of the sub-table.

◆ Datarow

The datarow object does not directly use constructor in the Code. Generally, a datarow object is created from a able with a certain structure using the newrow () method. A datarow has different States depending on whether it is independent, whether it belongs to a datatable, whether it has been modified, and whether it has been deleted by the datatable. It is published by the datarow. rowstate attribute, as shown in the following table:

Member name

Description

Added
This row has been added to datarowcollection, and acceptchanges has not been called. The ed row has been deleted using the delete method of datarow.

Deleted
This row has been deleted through the delete method of datarow.

Detached
This row has been created but does not belong to any datarowcollection. Datarow is in this status immediately after being created or added to or removed from the collection.

Modified
This row has been modified and acceptchanges has not been called.

Unchanged
This row has not been changed since the last acceptchanges call.

After a datarow object is created, its status is detached, which is an isolated object. Therefore, after datarow is created, the unit in datarow fills in data and then uses datatable. rows. the add (datarow) method adds this datarow to the able. After datarow is added to the able, the status of this datarow is changed to added. After the datarow is modified, the datarow status changes to modified. after the delete () method deletes datarow, The datarow status changes to deleted. However, this row still exists in the able, but the status changes. In this case, the datatable is used. rows. count to view the number of rows, which is the same as before deletion. This datarow is removed from the datatable only after the able. Remove (datarow) method is called, and its status also returns to the detached isolated state.

Once the datatable. after the acceptchanges () method, all rows are processed differently based on different states. The current values of added, modified, and unchanged are retained, and the rows of deleted are removed from the datatable, the status of all the last rows is set to unchanged. When the datatable is formed by filling in the dataadapter. Fill (dataset, datatable) method, the fill () method automatically calls the acceptchanges () method and sets the row status of the datatable to unchanged. In addition, if the specified datatable In the fill method does not exist in the dataset to be filled, a datatable with the same structure as the data source table will be generated and the data will be filled.

◆ Datarelation

Parent/child relationship between two able objects. Similar to the relationship between tables in a database, a parent table is equivalent to a table with a primary key and a child table with a foreign key. The datarelation constructor is generally: datarelation (string, datacolumn, datacolumn), string is the link name, the first datacolumn is the parent column of the link, and the second datacolumn is the Child column of the link, the ype values of the two columns that establish the relationship must be the same.

After the relationship is established, the relationship must be added to the parentrelations attribute or childrelations attribute of the able. These two attributes contain all the relationships between the table and the parent table and the relationship between the table and the child table. If this table is a parent table in the relationship, add the relationship to the childrelations set; otherwise, add it to the parentrelations set.

2. dataview

Dataview indicates a custom view of data that can be bound to a able for sorting, filtering, searching, editing, and navigation. Dataview can be compared with the database view, but it is a little different. The database view can be set up across tables, and dataview can only create a view for a single able. Dataview is generally created through the able. defaultview attribute, and then a subset of the datatable is created through the rowfilter attribute and the rowstatefilter attribute.

The rowfilter attribute is used to filter the expressions of the rows in the able. The expression is the same as the expression used to create a computed column as described above. For example: "lastname = 'Smith '", this is to view only the data rows whose lastname value is 'Smith.

The rowstatefilter attribute is used to set the row state filter in dataview. The preceding description introduces the status of datarow in datarow. A datarow may have five statuses, rowstatefilter is used to filter the row sets to be viewed. In fact, datarow not only has five statuses, but also has version issues. For example, if the datarow status is modified, that is, this row has been modified, then there will be two versions of datarow, current and original versions (before modification ). In fact, the rowstatefilter attribute is filtered by combining the status and version of datarow (rowstatefilter does save the value of currentrows). See the following table:

Member name

Description

Added
A new line.

Currentrows
Includes the current row that has not changed the row, new row, and modified row.

Deleted
Deleted rows.

Modifiedcurrent
The version of the current version and the original data (see modifiedoriginal.

Modifiedoriginal
Original Version (although it has been modified and exists in the form of modifiedcurrent ).

None
None.

Originalrows
Includes the original rows that have not been changed or deleted.

Unchanged
Unchanged rows.

The Count obtained by the dataview. Count attribute is the number of records in dataview after rowfilter and rowstatefilter are applied.

Dataview is based on the able. The dataview. Table attribute can obtain the datatable corresponding to the dataview. The row of dataview is called datarowview. You can obtain the datarow corresponding to this datarowview from datarowview directly through the datarowview. Row attribute.

3. gridview

The gridview in winform is usually bound with dataview to display the data in the able and modify the data in the datatable.
DOTNET's DataGrid has powerful functions, but it is not the same in terms of usage as it used to be, and sometimes it is quite troublesome. Therefore, many people are confused about this gridview and have a feeling of no way to start, as a matter of fact, we can solve many problems after figuring out some concepts.

The gridview binds the data source to be displayed through the datasource and datamember attributes. Data sources are generally datatable, dataview, and Dataset. However, when you bind these data sources to the gridview, dataview is actually bound. If the data source is datatable, it is actually bound to the defaultview of this datatable. If the data source is dataset, you can set a string to the datamember attribute, which specifies the table to bind, then bind the defaultview of the able specified by datamember to the gridview.

Therefore, the gridview displays the dataview filtered by the able.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.