DataTableCollection.Item[] Propriedade

Definição

Obtém o objeto DataTable especificado da coleção.Gets the specified DataTable object from the collection.

Sobrecargas

Item[Int32]

Obtém o objeto DataTable no índice especificado.Gets the DataTable object at the specified index.

Item[String]

Obtém o objeto DataTable com o nome especificado.Gets the DataTable object with the specified name.

Item[String, String]

Obtém o objeto DataTable com o nome especificado no namespace especificado.Gets the DataTable object with the specified name in the specified namespace.

Item[Int32]

Obtém o objeto DataTable no índice especificado.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

Parâmetros

index
Int32

O índice de base zero do DataTable a ser localizado.The zero-based index of the DataTable to find.

Valor da propriedade

DataTable

Um DataTable com o índice especificado, caso contrário, null se o DataTable não existir.A DataTable with the specified index; otherwise null if the DataTable does not exist.

Exceções

O valor de índice é maior que o número de itens na coleção.The index value is greater than the number of items in the collection.

Exemplos

O exemplo a seguir recupera um DataTable por seu índice.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

Comentários

Use o Contains método para determinar se existe uma tabela com um índice específico.Use the Contains method to determine whether a table with a specific index exists.

Se você tiver o nome de uma tabela, mas não seu índice, use o IndexOf método para retornar o índice.If you have the name of a table, but not its index, use the IndexOf method to return the index.

Confira também

Aplica-se a

Item[String]

Obtém o objeto DataTable com o nome especificado.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

Parâmetros

name
String

O nome do DataTable a ser localizado.The name of the DataTable to find.

Valor da propriedade

DataTable

Um DataTable com o nome especificado; caso contrário, null se o DataTable não existir.A DataTable with the specified name; otherwise null if the DataTable does not exist.

Exemplos

O exemplo a seguir recupera uma única tabela pelo nome do DataTableCollection .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

Comentários

Se DataTable existir um nome que corresponda ao caso da cadeia de caracteres de pesquisa, ele será retornado.If a DataTable name exists that matches the case of the search string, it is returned. Caso contrário, uma pesquisa que não diferencia maiúsculas de minúsculas é executada e, se DataTable for encontrado um nome que corresponda a essa pesquisa, ele será retornado.Otherwise a case-insensitive search is performed, and if a DataTable name is found that matches this search, it is returned.

Use o Contains método para determinar se existe uma tabela com um nome ou índice específico.Use the Contains method to determine whether a table with a specific name or index exists.

Aplica-se a

Item[String, String]

Obtém o objeto DataTable com o nome especificado no namespace especificado.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

Parâmetros

name
String

O nome do DataTable a ser localizado.The name of the DataTable to find.

tableNamespace
String

O nome do namespace DataTable a ser pesquisado.The name of the DataTable namespace to look in.

Valor da propriedade

DataTable

Um DataTable com o nome especificado; caso contrário, null se o DataTable não existir.A DataTable with the specified name; otherwise null if the DataTable does not exist.

Aplica-se a