DataTableCollection.IndexOf 方法

定義

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

多載

IndexOf(String, String)

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

IndexOf(DataTable)

取得指定 DataTable 物件的索引。

IndexOf(String)

取得在具有指定名稱之 DataTable 物件的集合中的索引。

IndexOf(String, String)

來源:
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

取得指定 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

取得在具有指定名稱之 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。 如果資料表名稱無法完全與單一資料表相符 (即有任何名稱語意模糊),呼叫就會失敗。

另請參閱

適用於