DataTableCollection.Item[] Propriété

Définition

Obtient l’objet spécifié DataTable de la collection.

Surcharges

Nom Description
Item[Int32]

Obtient l’objet DataTable à l’index spécifié.

Item[String]

Obtient l’objet DataTable portant le nom spécifié.

Item[String, String]

Obtient l’objet DataTable portant le nom spécifié dans l’espace de noms spécifié.

Item[Int32]

Obtient l’objet DataTable à l’index spécifié.

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

Paramètres

index
Int32

Index de base zéro de la DataTable recherche.

Valeur de propriété

Avec DataTable l’index spécifié ; sinon null , s’il DataTable n’existe pas.

Exceptions

La valeur d’index est supérieure au nombre d’éléments de la collection.

Exemples

L’exemple suivant récupère un DataTable 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

Remarques

Utilisez la Contains méthode pour déterminer si une table avec un index spécifique existe.

Si vous avez le nom d’une table, mais pas son index, utilisez la IndexOf méthode pour renvoyer l’index.

Voir aussi

S’applique à

Item[String]

Obtient l’objet DataTable portant le nom spécifié.

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

Paramètres

name
String

Nom de la DataTable recherche.

Valeur de propriété

Avec DataTable le nom spécifié ; sinon null , s’il DataTable n’existe pas.

Exemples

L’exemple suivant récupère une table unique par nom à partir du 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

Remarques

S’il existe un DataTable nom qui correspond au cas de la chaîne de recherche, il est retourné. Sinon, une recherche ne respectant pas la casse est effectuée et, si un DataTable nom est trouvé qui correspond à cette recherche, il est retourné.

Utilisez la Contains méthode pour déterminer si une table portant un nom ou un index spécifique existe.

S’applique à

Item[String, String]

Obtient l’objet DataTable portant le nom spécifié dans l’espace de noms spécifié.

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

Paramètres

name
String

Nom de la DataTable recherche.

tableNamespace
String

Nom de l’espace DataTable de noms à rechercher.

Valeur de propriété

Avec DataTable le nom spécifié ; sinon null , s’il DataTable n’existe pas.

S’applique à