The difference and usage of C # DataSet and DataTable

Source: Internet
Author: User

A DataSet is a DataSet, aDataTable is a data table, and a dataset stores multiple DataTable. Datasets and DataTable are like a container for storing data, which can exist when you query the database for some results.

The DataSet is powerful for browsing, sorting, searching, filtering, processing hierarchical data, caching changes, and so on, and can also be interchanged with XML data. The dataset can include multiple DataTable, which can be stored in a dataset to facilitate the operation of ADO. NET developers to facilitate the development of data processing, is a collection of DataReader, to solve the shortcomings of the design, DataReader data processing speed, but it is read-only, once moved to the next line can not view the previous row of data, the dataset can freely move the pointer. The data for the dataset is disconnected from the database. Datasets can also be used in multi-tier applications where the business object needs to pass the offline data structure to the client application if the application is running in a middle-tier business object to access the database.

Three ways to create a dataset:

A DataTable () Initializes a new instance of the DataTable class without parameters.
A DataTable (String tableName) Initializes a new instance of the DataTable class with the specified table name.


the common properties of the dataset are described in:
CaseSensitive indicates whether string comparisons in the table are case-sensitive. False if it is case-sensitive, and the default value is False.
ChildRelations gets the collection of child relationships for this DataTable.
Columns gets the collection of columns that belong to the table.
Constraints gets the collection of constraints maintained by the table.
The dataset gets the dataset to which this table belongs. DataSet related information, see my previous article "Data Access (2)-dataset"
DefaultView gets a custom view of a table that might include a filtered view or cursor position.
HasErrors gets a value that indicates whether there is an error in any row of any table of the dataset to which the table belongs.
Minimumcapacity Gets or sets the initial starting size of the table. The initial starting size of the rows in the table. The default value is 50.
Rows gets the collection of rows that belong to the table.
TableName Gets or sets the name of the DataTable.

DataSet Common methods:

Clear () Clears the DataTable for all data.
Clone () Clones the structure of a DataTable, including all DataTable schemas and constraints.
EndInit () ends the initialization of a DataTable that is used on a form or used by another component. Initialization occurs at run time.
ImportRow (DataRow Row) copies the DataRow into a DataTable, preserving any property settings as well as the initial and current values.
The merge (DataTable table) merges the specified DataTable with the current DataTable.
NewRow () Creates a new DataRow with the same schema as the table.
AcceptChanges () submits all changes made to the table since the last call to AcceptChanges ().
BeginInit () begins initializing a DataTable that is used on a form or used by another component. Initialization occurs at run time.

Ways to traverse a dataset

foreach (DataTable dt in dataset.tables)

foreach (DataRow dr in Dt. Rows)

foreach (DataColumn dc in Dr. Table.columns)

Console.WriteLine (DR[DC]);

The difference and usage of C # DataSet and DataTable

Related Article

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.