Breyta

Deila með


DataTableCollection.IndexOf Method

Definition

Gets the index in the collection of the specified DataTable object.

Overloads

IndexOf(String, String)

Gets the index in the collection of the specified DataTable object.

IndexOf(DataTable)

Gets the index of the specified DataTable object.

IndexOf(String)

Gets the index in the collection of the DataTable object with the specified name.

IndexOf(String, String)

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

Gets the index in the collection of the specified DataTable object.

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

Parameters

tableName
String

The name of the DataTable object to look for.

tableNamespace
String

The name of the DataTable namespace to look in.

Returns

The zero-based index of the DataTable with the specified name, or -1 if the table does not exist in the collection.

Examples

The following example returns the index of a named table in the 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

Remarks

You specify the name of the DataTable object by using the TableName property.

See also

Applies to

IndexOf(DataTable)

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

Gets the index of the specified DataTable object.

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

Parameters

table
DataTable

The DataTable to search for.

Returns

The zero-based index of the table, or -1 if the table is not found in the collection.

Examples

The following example returns the index of each table in the 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

Remarks

Use the IndexOf method to determine the exact index of a given table.

Before calling IndexOf, you can test for the existence of a table (specified by either index or name) by using the Contains method.

See also

Applies to

IndexOf(String)

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

Gets the index in the collection of the DataTable object with the specified name.

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

Parameters

tableName
String

The name of the DataTable object to look for.

Returns

The zero-based index of the DataTable with the specified name, or -1 if the table does not exist in the collection.

Examples

The following example returns the index of a named table in the 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

Remarks

You specify the name of the DataTable object by using the TableName property.

This method returns -1 when two or more tables have the same name but different namespaces. The call does not succeed if there is any ambiguity when matching a table name to exactly one table.

See also

Applies to