共用方式為


DataTableCollection.IndexOf 方法

定義

取得指定 DataTable 物件集合中的索引。

多載

名稱 Description
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

備註

你可以用屬性TableName來指定物件名稱DataTable

另請參閱

適用於

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

備註

你可以用屬性TableName來指定物件名稱DataTable

當兩個或多個資料表名稱相同但命名空間不同時,此方法會回傳 -1。 若在將資料表名稱與單一資料表匹配時有任何歧義,則呼叫不成功。

另請參閱

適用於