DataTableCollection.Contains Method (String, String)

Note: This method is new in the .NET Framework version 2.0.

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

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

public bool Contains (
	string name,
	string tableNamespace
)
public boolean Contains (
	String name, 
	String tableNamespace
)
public function Contains (
	name : String, 
	tableNamespace : String
) : boolean

Parameters

name

The name of the DataTable to find.

tableNamespace

The name of the DataTable namespace to look in.

Return Value

true if the specified table exists; otherwise false.

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.

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

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");


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0
Show: