DataTableCollection.IndexOf Méthode

Définition

Obtient l'index de l'objet DataTable spécifié dans la collection.

Surcharges

IndexOf(String, String)

Obtient l'index de l'objet DataTable spécifié dans la collection.

IndexOf(DataTable)

Obtient l'index de l'objet DataTable spécifié.

IndexOf(String)

Obtient l'index de l'objet DataTable portant le nom spécifié dans la collection.

IndexOf(String, String)

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

Obtient l'index de l'objet DataTable spécifié dans la collection.

public:
 int IndexOf(System::String ^ tableName, System::String ^ tableNamespace);
public int IndexOf (string tableName, string tableNamespace);
member this.IndexOf : string * string -> int
Public Function IndexOf (tableName As String, tableNamespace As String) As Integer

Paramètres

tableName
String

Nom de l'objet DataTable à rechercher.

tableNamespace
String

Nom de l'espace de noms DataTable dans lequel rechercher.

Retours

Index de base zéro du DataTable portant le nom spécifié, ou -1 si la table n'existe pas dans la collection.

Exemples

L’exemple suivant retourne l’index d’une table nommée dans le DataTableCollection.

private void GetIndexes()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tables = thisDataSet.Tables;

    // Get the index of the table named "Authors", if it exists.
    if (tables.Contains("Authors"))
        System.Diagnostics.Debug.WriteLine(tables.IndexOf("Authors"));
}
Private Sub GetIndexes()
   ' Get the DataSet of a DataGrid.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

   ' Get the DataTableCollection through the Tables property.
   Dim tables As DataTableCollection = thisDataSet.Tables

   ' Get the index of the table named "Authors", if it exists.
   If tables.Contains("Authors") Then
      System.Diagnostics.Debug.WriteLine(tables.IndexOf("Authors"))
   End If
End Sub

Remarques

Vous spécifiez le nom de l’objet à l’aide DataTable de la TableName propriété .

Voir aussi

S’applique à

IndexOf(DataTable)

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

Obtient l'index de l'objet DataTable spécifié.

public:
 int IndexOf(System::Data::DataTable ^ table);
public:
 virtual int IndexOf(System::Data::DataTable ^ table);
public int IndexOf (System.Data.DataTable? table);
public int IndexOf (System.Data.DataTable table);
public virtual int IndexOf (System.Data.DataTable table);
member this.IndexOf : System.Data.DataTable -> int
abstract member IndexOf : System.Data.DataTable -> int
override this.IndexOf : System.Data.DataTable -> int
Public Function IndexOf (table As DataTable) As Integer
Public Overridable Function IndexOf (table As DataTable) As Integer

Paramètres

table
DataTable

DataTable à rechercher.

Retours

Index de base zéro de la table ou -1 si la table est introuvable dans la collection.

Exemples

L’exemple suivant retourne l’index de chaque table dans le DataTableCollection.

private void GetIndexes()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tables = thisDataSet.Tables;

    // Get the index of each table in the collection.
    foreach (DataTable table in tables)
        System.Diagnostics.Debug.WriteLine(tables.IndexOf(table));
}
Private Sub GetIndexes()
    ' Get the DataSet of a DataGrid.
    Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

    ' Get the DataTableCollection through the Tables property.
    Dim tables As DataTableCollection = thisDataSet.Tables
    Dim table As DataTable

    ' Get the index of each table in the collection.
    For Each table In tables
       System.Diagnostics.Debug.WriteLine(tables.IndexOf(table))
    Next
End Sub

Remarques

Utilisez la IndexOf méthode pour déterminer l’index exact d’une table donnée.

Avant d’appeler IndexOf, vous pouvez tester l’existence d’une table (spécifiée par l’index ou le nom) à l’aide de la Contains méthode .

Voir aussi

S’applique à

IndexOf(String)

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

Obtient l'index de l'objet DataTable portant le nom spécifié dans la collection.

public:
 int IndexOf(System::String ^ tableName);
public:
 virtual int IndexOf(System::String ^ tableName);
public int IndexOf (string? tableName);
public int IndexOf (string tableName);
public virtual int IndexOf (string tableName);
member this.IndexOf : string -> int
abstract member IndexOf : string -> int
override this.IndexOf : string -> int
Public Function IndexOf (tableName As String) As Integer
Public Overridable Function IndexOf (tableName As String) As Integer

Paramètres

tableName
String

Nom de l'objet DataTable à rechercher.

Retours

Index de base zéro du DataTable portant le nom spécifié, ou -1 si la table n'existe pas dans la collection.

Exemples

L’exemple suivant retourne l’index d’une table nommée dans le DataTableCollection.

private void GetIndexes()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tables = thisDataSet.Tables;

    // Get the index of the table named "Authors", if it exists.
    if (tables.Contains("Authors"))
        System.Diagnostics.Debug.WriteLine(tables.IndexOf("Authors"));
}
Private Sub GetIndexes()
   ' Get the DataSet of a DataGrid.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

   ' Get the DataTableCollection through the Tables property.
   Dim tables As DataTableCollection = thisDataSet.Tables

   ' Get the index of the table named "Authors", if it exists.
   If tables.Contains("Authors") Then
      System.Diagnostics.Debug.WriteLine(tables.IndexOf("Authors"))
   End If
End Sub

Remarques

Vous spécifiez le nom de l’objet à l’aide DataTable de la TableName propriété .

Cette méthode retourne -1 lorsque deux tables ou plus ont le même nom, mais des espaces de noms différents. L'appel ne réussit pas en cas d'ambiguïté lors de la mise en correspondance d'un nom de table avec exactement une table.

Voir aussi

S’applique à