DataTableCollection.Item[] Propriedade

Definição

Obtém o objeto especificado DataTable da coleção.

Sobrecargas

Name Description
Item[Int32]

Obtém o DataTable objeto no índice especificado.

Item[String]

Obtém o DataTable objeto com o nome especificado.

Item[String, String]

Obtém o DataTable objeto com o nome especificado no espaço de nomes especificado.

Item[Int32]

Obtém o DataTable objeto no índice especificado.

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 baseado em zero do DataTable para encontrar.

Valor de Propriedade

A DataTable com o índice especificado; caso contrário null , se o DataTable não existir.

Exceções

O valor do índice é superior ao número de itens na coleção.

Exemplos

O exemplo seguinte recupera a DataTable pelo seu índice.

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

Observações

Use o Contains método para determinar se existe uma tabela com um índice específico.

Se tiver o nome de uma tabela, mas não o seu índice, use o IndexOf método para devolver o índice.

Ver também

Aplica-se a

Item[String]

Obtém o DataTable objeto com o nome especificado.

public:
 property System::Data::DataTable ^ default[System::String ^] { System::Data::DataTable ^ get(System::String ^ name); };
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 encontrar.

Valor de Propriedade

A DataTable com o nome especificado; caso contrário null , se o DataTable não existir.

Exemplos

O exemplo seguinte recupera uma única tabela pelo nome do 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

Observações

Se existir um DataTable nome que corresponda ao caso da cadeia de pesquisa, ele é devolvido. Caso contrário, é realizada uma pesquisa insensível a maiúsculas e minúsculas e, se for encontrado um DataTable nome que corresponda a essa pesquisa, ele é devolvido.

Use o Contains método para determinar se existe uma tabela com um nome ou índice específico.

Aplica-se a

Item[String, String]

Obtém o DataTable objeto com o nome especificado no espaço de nomes especificado.

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; }
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 encontrar.

tableNamespace
String

O nome do DataTable espaço de nomes para consultar.

Valor de Propriedade

A DataTable com o nome especificado; caso contrário null , se o DataTable não existir.

Aplica-se a