DataTable and DataSet

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/rjf1979/archive/2010/09/09/1822667.html

The dataset contains a number of DataTable
A table with a DataTable can be, more than one table with a dataset (a DataTable is a table, a dataset is a collection of tables.) )
A dataset can be thought of as a database in memory, and a DataTable is a table in a database.

(Note: A DataTable is a table, and a DataSet is a collection of tables)

=============================
A dataset is an offline container for data. It does not contain the concept of a database connection, and the data that is actually stored in the dataset does not necessarily originate from the database. A dataset (dataset) consists of a set of data tables, each of which has columns of data and rows of data. In addition to defining data, you can define links between tables in a dataset.

A data table is very similar to a physical database table, which consists of some columns with specific attributes, which may contain 0 or more rows of data. A data table can also define a primary key code (which can be a column or columns), or a column can contain constraints.
----
The above text is excerpted from the relevant chapters of the 3rd edition of C # advanced programming

============================================

You can think of a DataTable and a dataset as a data container, such as when you query a database and get some results that you can put into this container, you might want to ask: I do not use this container, I read the variable or array can also be stored up Ah, why the container?

The reason is that this kind of container is more powerful and can be used in addition to saving data. Example: In a C/s structure of the desktop database system, you can store the query results in front of the container data display to your client interface, the user in the interface to add, delete, modify the user's operations can be updated to the container, and so the user operation is complete, the request for updates, And then you update the container's entire data changes to the central database, what are the benefits? is to reduce the database operation, the client speed increased, the database pressure is reduced.

A dataset can be likened to an in-memory database, a DataTable is an in-memory data table, and a dataset can store multiple DataTable
DataSet you can think of him as a database that can include tables, views, and so on.

DataTable: Data table.
One:
SqlDataAdapter Da=new SqlDataAdapter (CMD);
DataTable dt=new DataTable ();
Da. Fill (DT);
-----------------
Put the data results directly into the DataTable,
Two:
SqlDataAdapter Da=new SqlDataAdapter (CMD);
DataSet dt=new DataSet ();
Da. Fill (DT);
----------------
Data results in a dataset, to use that DataTable, you can: Dataset[0]
More common usage:
SqlDataAdapter Da=new SqlDataAdapter (CMD);
DataSet dt=new DataSet ();
Da. Fill (DT, "Table1");
When used: This takes the DataTable:
dataset["Table1"]

DataTable and DataSet

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.