Item Property (String)
Collapse the table of content
Expand the table of content

DataTableCollection.Item Property (String)


Gets the DataTable object with the specified name.

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

public DataTable this[
	string name
] { get; }


Type: System.String

The name of the DataTable to find.

Property Value

Type: System.Data.DataTable

A DataTable with the specified name; otherwise null if the DataTable does not exist.

If a DataTable name exists that matches the case of the search string, it is returned. Otherwise a case-insensitive search is performed, and if a DataTable name is found that matches this search, it is returned.

Use the Contains method to determine whether a table with a specific name or index exists.

The following example retrieves a single table by name from the DataTableCollection.

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

    // Get the DataTableCollection.
    DataTableCollection tablesCollection = thisDataSet.Tables;

    // Get a specific table by name.
    DataTable table = tablesCollection["Suppliers"];

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft