Gets the table in the collection with the given name (not case-sensitive).
[C#] In C#, this member is the indexer for the TablesCollection class.
[Visual Basic] Overloads Public Default ReadOnly Property Item( _ ByVal name As String _ ) As DataTable [C#] public DataTable this[ string name ] {get;} [C++] public: __property DataTable* get_Item( String* name ); [JScript] returnValue = TablesCollectionObject.Item(name); -or- returnValue = TablesCollectionObject(name);
[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed Item property whose type is Object and whose index type is String.
A DataTable with the specified name.
Exception Type | Condition |
---|---|
TableOutOfRange(System.Int32) | The table name does not exist in the collection. |
The Contains method can be used to determine if a table with a specified name or index exists.
The following example retrieves a single table by name from the TablesCollection.
[Visual Basic]
Private Sub GetTableByName() Dim tablesCol As TablesCollection Dim dSet As DataSet Dim t As DataTable ' Presuming a DataGrid is displaying more than one table, get its DataSet. Set dSet = DataGrid1.DataGridTable.DataTable.DataSet ' Get the TablesCollection. Set tablesCol = dSet.Tables ' Get a specific table by name. Set t = tablesCol("Suppliers") Console.WriteLine(t.TableName) End Sub
TablesCollection Class | TablesCollection Members | System.Data Namespace | TablesCollection.Item Overload List