The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataTable Class

Represents one table of in-memory data.

Namespace: System.Data
Assembly: System.Data (in

public ref class DataTable : public MarshalByValueComponent, IListSource, ISupportInitializeNotification, ISupportInitialize, 
	ISerializable, IXmlSerializable
/** @attribute SerializableAttribute() */ 
public class DataTable extends MarshalByValueComponent implements IListSource, ISupportInitializeNotification, 
	ISupportInitialize, ISerializable, IXmlSerializable
public class DataTable extends MarshalByValueComponent implements IListSource, ISupportInitializeNotification, 
	ISupportInitialize, ISerializable, IXmlSerializable
Not applicable.

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

When accessing DataTable objects, note that they are conditionally case sensitive. For example, if one 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 DataSet can contain two DataTable objects that have the same TableName property value but different Namespace property values. For more information about working with DataTable objects, see Creating a DataTable.

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

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

The DataTable also contains a collection of 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 DataTable events that can be used to determine when changes are made to a table. These include RowChanged, RowChanging, RowDeleting, and RowDeleted. For more information about the events that can be used with a DataTable, see Working with DataTable Events.

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


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

How to: Create DataTablesData Access in Visual Studio

The following example creates two DataTable objects and one DataRelation object, and adds the new objects to a DataSet. The tables are then displayed in a DataGridView control.

No code example is currently available or this language may not be supported.

This type is safe for multithreaded read operations. You must synchronize any write operations.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft