DataTableCollection.Add Method (String, String)

Creates a DataTable object by using the specified name and adds it to the collection.

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

public DataTable Add (
	string name,
	string tableNamespace
public DataTable Add (
	String name, 
	String tableNamespace
public function Add (
	name : String, 
	tableNamespace : String
) : DataTable
Not applicable.



The name to give the created DataTable.


The namespace to give the created DataTable.

Return Value

The newly created DataTable.

Exception typeCondition


A table in the collection has the same name. (The comparison is not case sensitive.)

If either a null reference (Nothing in Visual Basic) or an empty string ("") is passed in, a default name is given to the newly created DataTable. This name is based on the order in which the table was added ("Table1", "Table2", and so on).

The CollectionChanged event occurs if the table is successfully added to the collection.

The following example adds a DataTable with the given name to the DataTableCollection.

private void AddTable()
    // Presuming a DataGrid is displaying more than one table, 
    // get its DataSet.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Use the Add method to add a new table with a given name.
    DataTable table = thisDataSet.Tables.Add("NewTable");

    // Code to add columns and rows not shown here.


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

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0