DataTableCollection.IndexOf 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取指定 DataTable 对象的集合中的索引。
重载
| IndexOf(String, String) | 获取指定 DataTable 对象的集合中的索引。 | 
| IndexOf(DataTable) | 获取指定 DataTable 对象的索引。 | 
| IndexOf(String) | 获取具有指定名称的 DataTable 对象的集合中的索引。 | 
IndexOf(String, String)
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
获取指定 DataTable 对象的集合中的索引。
public:
 int IndexOf(System::String ^ tableName, System::String ^ tableNamespace);public int IndexOf (string tableName, string tableNamespace);member this.IndexOf : string * string -> intPublic Function IndexOf (tableName As String, tableNamespace As String) As Integer参数
返回
具有指定名称的 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)
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
- Source:
- 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 -> intabstract member IndexOf : System.Data.DataTable -> int
override this.IndexOf : System.Data.DataTable -> intPublic Function IndexOf (table As DataTable) As IntegerPublic 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之前,可以使用 方法测试是否存在由 index 或 name) 指定的表 (Contains 。
另请参阅
适用于
IndexOf(String)
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
- Source:
- 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 -> intabstract member IndexOf : string -> int
override this.IndexOf : string -> intPublic Function IndexOf (tableName As String) As IntegerPublic 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。 如果在将表名只匹配到一个表时存在任何二义性,则该调用不会成功。