DataTableCollection.IndexOf Método

Definición

Obtiene el índice del objeto DataTable especificado en la colección.

Sobrecargas

IndexOf(String, String)

Obtiene el índice del objeto DataTable especificado en la colección.

IndexOf(DataTable)

Obtiene el índice del objeto DataTable especificado.

IndexOf(String)

Obtiene el índice del objeto DataTable con el nombre especificado en la colección.

IndexOf(String, String)

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

Obtiene el índice del objeto DataTable especificado en la colección.

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

Parámetros

tableName
String

Nombre del objeto DataTable que se desea buscar.

tableNamespace
String

Nombre del espacio de nombres de DataTable en el que se va a buscar.

Devoluciones

Índice de base cero del objeto DataTable con el nombre especificado o -1 si la tabla no existe en la colección.

Ejemplos

En el ejemplo siguiente se devuelve el índice de una tabla con nombre en .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

Comentarios

Especifique el nombre del DataTable objeto mediante la TableName propiedad .

Consulte también

Se aplica a

IndexOf(DataTable)

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

Obtiene el índice del objeto DataTable especificado.

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

Parámetros

table
DataTable

DataTable que se va a buscar.

Devoluciones

Índice de base cero de la tabla, o -1 si la tabla no se encuentra en la colección.

Ejemplos

En el ejemplo siguiente se devuelve el índice de cada tabla de 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

Comentarios

Use el IndexOf método para determinar el índice exacto de una tabla determinada.

Antes de llamar a IndexOf, puede probar la existencia de una tabla (especificada por índice o nombre) mediante el Contains método .

Consulte también

Se aplica a

IndexOf(String)

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

Obtiene el índice del objeto DataTable con el nombre especificado en la colección.

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

Parámetros

tableName
String

Nombre del objeto DataTable que se desea buscar.

Devoluciones

Índice de base cero del objeto DataTable con el nombre especificado o -1 si la tabla no existe en la colección.

Ejemplos

En el ejemplo siguiente se devuelve el índice de una tabla con nombre en .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

Comentarios

Especifique el nombre del DataTable objeto mediante la TableName propiedad .

Este método devuelve -1 cuando dos o más tablas tienen el mismo nombre, pero espacios de nombres diferentes. Se producirá un error en la llamada si existe alguna ambigüedad al hacer coincidir exactamente una tabla con su nombre de tabla.

Consulte también

Se aplica a