Поделиться через


DataTableCollection.IndexOf Метод

Определение

Возвращает индекс в коллекции указанного DataTable объекта.

Перегрузки

Имя Описание
IndexOf(String, String)

Возвращает индекс в коллекции указанного DataTable объекта.

IndexOf(DataTable)

Возвращает индекс указанного DataTable объекта.

IndexOf(String)

Возвращает индекс в коллекции DataTable объекта с указанным именем.

IndexOf(String, String)

Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs

Возвращает индекс в коллекции указанного DataTable объекта.

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

Параметры

tableName
String

Имя объекта для DataTable поиска.

tableNamespace
String

Имя DataTable пространства имен для поиска.

Возвращаемое значение

Отсчитываемый от нуля индекс указанного DataTable имени или -1, если таблица не существует в коллекции.

Примеры

В следующем примере возвращается индекс именованной таблицы в объекте 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

Комментарии

Укажите имя DataTable объекта с помощью TableName свойства.

См. также раздел

Применяется к

IndexOf(DataTable)

Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs

Возвращает индекс указанного DataTable объекта.

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

Параметры

table
DataTable

Поиск DataTable .

Возвращаемое значение

Отсчитываемый от нуля индекс таблицы или -1, если таблица не найдена в коллекции.

Примеры

В следующем примере возвращается индекс каждой таблицы в таблице 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

Комментарии

IndexOf Используйте метод, чтобы определить точный индекс заданной таблицы.

Перед вызовом IndexOfможно проверить существование таблицы (указанной индексом или именем) с помощью Contains метода.

См. также раздел

Применяется к

IndexOf(String)

Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs

Возвращает индекс в коллекции DataTable объекта с указанным именем.

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

Параметры

tableName
String

Имя объекта для DataTable поиска.

Возвращаемое значение

Отсчитываемый от нуля индекс указанного DataTable имени или -1, если таблица не существует в коллекции.

Примеры

В следующем примере возвращается индекс именованной таблицы в объекте 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

Комментарии

Укажите имя DataTable объекта с помощью TableName свойства.

Этот метод возвращает -1, если две или несколько таблиц имеют одно и то же имя, но разные пространства имен. Вызов не выполняется, если при сопоставлении имени таблицы с одной таблицей возникает неоднозначность.

См. также раздел

Применяется к