DataTableCollection.Contains Method

Definition

Gets a value indicating whether a DataTable object with the specified name exists in the collection.

Overloads

Contains(String)

Gets a value that indicates whether a DataTable object with the specified name exists in the collection.

Contains(String, String)

Gets a value that indicates whether a DataTable object with the specified name and table namespace exists in the collection.

Contains(String)

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

Gets a value that indicates whether a DataTable object with the specified name exists in the collection.

C#
public bool Contains(string? name);
C#
public bool Contains(string name);

Parameters

name
String

The name of the DataTable to find.

Returns

true if the specified table exists; otherwise false.

Examples

The following example tests whether a table with the name "Suppliers" exists in the DataTableCollection.

C#
private void TestForTableName()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tablesCol = thisDataSet.Tables;

    // Check if the named table exists.
    if (tablesCol.Contains("Suppliers"))
        Console.WriteLine("Table named Suppliers exists");
}

Remarks

You specify the name of the DataTable object by using the TableName property. If you add a DataTable to the collection with the Add method, passing no arguments, the table is given a default name, based on the order in which the table was added ("Table1", "Table2", and so on).

To get the index of a DataTable, use the IndexOf method.

Poznámka

Returns false 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

.NET 10 a ďalšie verzie
Produkt Verzie
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Contains(String, String)

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

Gets a value that indicates whether a DataTable object with the specified name and table namespace exists in the collection.

C#
public bool Contains(string name, string tableNamespace);

Parameters

name
String

The name of the DataTable to find.

tableNamespace
String

The name of the DataTable namespace to look in.

Returns

true if the specified table exists; otherwise false.

Examples

The following example tests whether a table with the name "Suppliers" exists in the DataTableCollection.

C#
private void TestForTableName()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tablesCol = thisDataSet.Tables;

    // Check if the named table exists.
    if (tablesCol.Contains("Suppliers"))
        Console.WriteLine("Table named Suppliers exists");
}

Remarks

You specify the name of the DataTable object by using the TableName property. If you add a DataTable to the collection with the Add method, passing no arguments, the table is given a default name, based on the order in which the table was added ("Table1", "Table2", and so on).

Poznámka

Returns false 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.

To get the index of a DataTable, use the IndexOf method.

See also

Applies to

.NET 10 a ďalšie verzie
Produkt Verzie
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1