Επεξεργασία

Κοινή χρήση μέσω


DataTableCollection.Item[] Property

Definition

Gets the specified DataTable object from the collection.

Overloads

Item[Int32]

Gets the DataTable object at the specified index.

Item[String]

Gets the DataTable object with the specified name.

Item[String, String]

Gets the DataTable object with the specified name in the specified namespace.

Item[Int32]

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs

Gets the DataTable object at the specified index.

public:
 property System::Data::DataTable ^ default[int] { System::Data::DataTable ^ get(int index); };
public System.Data.DataTable this[int index] { get; }
member this.Item(int) : System.Data.DataTable
Default Public ReadOnly Property Item(index As Integer) As DataTable

Parameters

index
Int32

The zero-based index of the DataTable to find.

Property Value

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

Exceptions

The index value is greater than the number of items in the collection.

Examples

The following example retrieves a DataTable by its index.

private void GetDataTableByIndex()
{
   // presuming a DataGrid is displaying more than one table, get its DataSet.
   DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
   // Get the DataTableCollection.
   DataTableCollection tablesCollection = thisDataSet.Tables;
   // Iterate through the collection to get each table name.
   for (int i = 0; i < tablesCollection.Count; i++)
      Console.WriteLine(tablesCollection[i].TableName);
}
Private Sub GetDataTableByIndex()
    ' 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

    ' Iterate through the collection to get each table name.
    Dim i As Integer
    For i = 0 To tablesCollection.Count - 1
       Console.WriteLine(tablesCollection(i).TableName)
    Next
End Sub

Remarks

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

If you have the name of a table, but not its index, use the IndexOf method to return the index.

See also

Applies to

Item[String]

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs

Gets the DataTable object with the specified name.

public:
 property System::Data::DataTable ^ default[System::String ^] { System::Data::DataTable ^ get(System::String ^ name); };
public System.Data.DataTable? this[string? name] { get; }
public System.Data.DataTable this[string name] { get; }
member this.Item(string) : System.Data.DataTable
Default Public ReadOnly Property Item(name As String) As DataTable

Parameters

name
String

The name of the DataTable to find.

Property Value

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

Examples

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"];
    Console.WriteLine(table.TableName);
}
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

Remarks

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.

Applies to

Item[String, String]

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs

Gets the DataTable object with the specified name in the specified namespace.

public:
 property System::Data::DataTable ^ default[System::String ^, System::String ^] { System::Data::DataTable ^ get(System::String ^ name, System::String ^ tableNamespace); };
public System.Data.DataTable? this[string? name, string tableNamespace] { get; }
public System.Data.DataTable this[string name, string tableNamespace] { get; }
member this.Item(string * string) : System.Data.DataTable
Default Public ReadOnly Property Item(name As String, tableNamespace As String) As DataTable

Parameters

name
String

The name of the DataTable to find.

tableNamespace
String

The name of the DataTable namespace to look in.

Property Value

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

Applies to