DataTablesDataTables

DataSet 由表、关系和约束的集合组成。A DataSet is made up of a collection of tables, relationships, and constraints. 在 ADO.NET 中DataTable ,对象用于表示数据集中的表。In ADO.NET, DataTable objects are used to represent the tables in a DataSet. DataTable表示内存中关系数据的一个表;数据是的本地数据。它所在的基于网络的应用程序,但可以使用DataAdapter从数据源(例如 Microsoft SQL Server)进行填充。有关详细信息,请参阅从 DataAdapter 填充数据集A DataTable represents one table of in-memory relational data; the data is local to the .NET-based application in which it resides, but can be populated from a data source such as Microsoft SQL Server using a DataAdapter For more information, see Populating a DataSet from a DataAdapter.

DataTable类是 .NET Framework 类库中的system.object命名空间的成员。The DataTable class is a member of the System.Data namespace within the .NET Framework class library. 您可以独立创建和使用datatable ,或将其作为数据集的成员,也可以将datatable对象与其他DataView.NET Framework 对象结合使用,其中包括。You can create and use a DataTable independently or as a member of a DataSet, and DataTable objects can also be used in conjunction with other .NET Framework objects, including the DataView. 通过dataset对象的Tables属性访问数据集中的表的集合。You access the collection of tables in a DataSet through the Tables property of the DataSet object.

表的架构或结构由列和约束表示。The schema, or structure of a table is represented by columns and constraints. 使用 DataColumn对象以及和UniqueConstraint对象定义 DataTable 的架构。 ForeignKeyConstraintYou define the schema of a DataTable using DataColumn objects as well as ForeignKeyConstraint and UniqueConstraint objects. 表中的列可以映射到数据源中的列、包含从表达式计算所得的值、自动递增它们的值,或包含主键值。The columns in a table can map to columns in a data source, contain calculated values from expressions, automatically increment their values, or contain primary key values.

除了架构以外, DataTable还必须有行来包含和排序数据。In addition to a schema, a DataTable must also have rows to contain and order data. DataRow 类表示表中包含的实际数据。The DataRow class represents the actual data contained in a table. 使用DataRow及其属性和方法可以检索、计算和处理表中的数据。You use the DataRow and its properties and methods to retrieve, evaluate, and manipulate the data in a table. 访问和更改行中的数据时, DataRow对象将同时维护其当前状态和原始状态。As you access and change the data within a row, the DataRow object maintains both its current and original state.

您可以使用表中的一个或多个相关的列来创建表与表之间的父子关系。You can create parent-child relationships between tables using one or more related columns in the tables. 使用DataRelation创建DataTable对象之间的关系。You create a relationship between DataTable objects using a DataRelation. 然后,可以使用DataRelation对象返回特定行的相关子行或父行。DataRelation objects can then be used to return the related child or parent rows of a particular row. 有关详细信息,请参阅添加 datarelationFor more information, see Adding DataRelations.

本节内容In This Section

创建数据表Creating a DataTable
说明如何创建DataTable并将其添加到数据集Explains how to create a DataTable and add it to a DataSet.

数据表架构定义DataTable Schema Definition
提供有关创建和使用DataColumn对象和约束的信息。Provides information about creating and using DataColumn objects and constraints.

操作数据表中的数据Manipulating Data in a DataTable
说明如何添加、修改和删除表中的数据。Explains how to add, modify, and delete data in a table. 说明如何使用DataTable事件来检查对表中数据的更改。Explains how to use DataTable events to examine changes to data in the table.

处理数据表事件Handling DataTable Events
提供可用于DataTable的事件的相关信息,包括修改列值和添加或删除行时的事件。Provides information about the events available for use with a DataTable, including events when column values are modified and rows are added or deleted.

ADO.NETADO.NET
描述 ADO.NET 结构和组件,并说明如何用来访问现有的数据源和管理应用程序数据。Describes the ADO.NET architecture and components, and how to use them to access existing data sources and manage application data.

数据集、数据表和数据视图DataSets, DataTables, and DataViews
提供有关 ADO.NET数据集的信息,包括如何创建表之间的关系。Provides information about the ADO.NET DataSet including how to create relationships between tables.

Constraint
提供有关约束对象的参考信息。Provides reference information about the Constraint object.

DataColumn
提供有关DataColumn对象的参考信息。Provides reference information about the DataColumn object.

DataSet
提供有关DataSet对象的参考信息。Provides reference information about the DataSet object.

DataTable
提供有关DataTable对象的参考信息。Provides reference information about the DataTable object.

类库概述Class Library Overview
提供 .NET Framework 类库的概述,包括System命名空间及其第二级命名空间、 system.webProvides an overview of the .NET Framework class library, including the System namespace as well as its second-level namespace, System.Data.

请参阅See also