System.Data.DataTable Class

Represents one table of in-memory data.

See Also: DataTable Members

Syntax

[System.Xml.Serialization.XmlSchemaProvider("GetDataTableSchema")]
[System.ComponentModel.Editor("Microsoft.VSDesigner.Data.Design.DataTableEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.DesignTimeVisible(false)]
[System.ComponentModel.DefaultProperty("TableName")]
[System.ComponentModel.DefaultEvent("RowChanging")]
[System.ComponentModel.ToolboxItem(false)]
public class DataTable : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitializeNotification, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable

Remarks

The System.Data.DataTable is a central object in the ADO.NET library. Other objects that use the System.Data.DataTable include the System.Data.DataSet and the System.Data.DataView.

When accessing System.Data.DataTable objects, note that they are conditionally case sensitive. For example, if one System.Data.DataTable is named "mydatatable" and another is named "Mydatatable", a string used to search for one of the tables is regarded as case sensitive. However, if "mydatatable" exists and "Mydatatable" does not, the search string is regarded as case insensitive. A System.Data.DataSet can contain two System.Data.DataTable objects that have the same DataTable.TableName property value but different DataTable.Namespace property values. For more information about working with System.Data.DataTable objects, see Creating a DataTable.

If you are creating a System.Data.DataTable programmatically, you must first define its schema by adding System.Data.DataColumn objects to the System.Data.DataColumnCollection (accessed through the DataTable.Columns property). For more information about adding System.Data.DataColumn objects, see Adding Columns to a Table.

To add rows to a System.Data.DataTable, you must first use the DataTable.NewRow method to return a new System.Data.DataRow object. The DataTable.NewRow method returns a row with the schema of the System.Data.DataTable, as it is defined by the table's System.Data.DataColumnCollection. The maximum number of rows that a System.Data.DataTable can store is 16,777,216. For more information, see Adding Data to a Table.

The System.Data.DataTable also contains a collection of System.Data.Constraint objects that can be used to ensure the integrity of the data. For more information, see Adding Constraints to a Table.

There are many System.Data.DataTable events that can be used to determine when changes are made to a table. These include DataTable.RowChanged, DataTable.RowChanging, DataTable.RowDeleting, and DataTable.RowDeleted. For more information about the events that can be used with a System.Data.DataTable, see Working with DataTable Events.

When an instance of System.Data.DataTable is created, some of the read/write properties are set to initial values. For a list of these values, see the DataTable.#ctor constructor topic.

Note:

The System.Data.DataSet and System.Data.DataTable objects inherit from System.ComponentModel.MarshalByValueComponent, and support the System.Runtime.Serialization.ISerializable interface for .NET Framework remoting. These are the only ADO.NET objects that you can use for .NET Framework remoting.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0