DataTableCollection.Item[] Propriedade

Definição

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

Sobrecargas

Nome 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 namespace 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 da localização DataTable .

Valor da propriedade

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

Exceções

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

Exemplos

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

Comentários

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

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

Confira 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 da localização DataTable .

Valor da propriedade

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

Exemplos

O exemplo a seguir recupera uma única tabela por 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

Comentários

Se existir um DataTable nome que corresponda ao caso da cadeia de caracteres de pesquisa, ele será retornado. Caso contrário, uma pesquisa que não diferencia maiúsculas de minúsculas será executada e, se for encontrado um DataTable nome que corresponda a essa pesquisa, ela será retornada.

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 namespace 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 da localização DataTable .

tableNamespace
String

O nome do DataTable namespace a ser olhado.

Valor da propriedade

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

Aplica-se a