DataTableCollection.Contains Method (String, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

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

Public Function Contains (
	name As String,
	tableNamespace As String
) As Boolean


Type: System.String

The name of the DataTable to find.

Type: System.String

The name of the DataTable namespace to look in.

Return Value

Type: System.Boolean

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).


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.

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

Private Sub TestForTableName()
   ' Get the DataSet of a DataGrid.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

   ' Get the DataTableCollection through the Tables property.
   Dim tablesCol As DataTableCollection = thisDataSet.Tables

   ' Check if the named table exists.
   If tablesCol.Contains("Suppliers") Then 
      Console.WriteLine("Table named Suppliers exists")
   End If
End Sub

.NET Framework
Available since 2.0
Return to top