DataTableCollection.Item Property (String)

 

Gets the DataTable object with the specified name.

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

Public ReadOnly Property Item (
	name As String
) As DataTable

Parameters

name
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 Sub GetTableByName()
    ' Presuming a DataGrid is displaying more than one table, 
    ' get its DataSet.
    Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

    ' Get the DataTableCollection.
    Dim tablesCollection As DataTableCollection = thisDataSet.Tables

    ' Get a specific table by name.
    Dim table As DataTable = tablesCollection("Suppliers")
    Console.WriteLine(table.TableName)
End Sub

.NET Framework
Available since 1.1
Return to top
Show: