Gets a value indicating whether a DataTable object with the specified name exists in the collection.
[Visual Basic] Public Function Contains( _ ByVal name As String _ ) As Boolean [C#] public bool Contains( string name ); [C++] public: bool Contains( String* name ); [JScript] public function Contains( name : String ) : Boolean;
true if the specified table exists; otherwise, false.
You specify the name of the DataTable object by means of 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.
[Visual Basic, C#] The following example tests whether a table with the name "Suppliers" exists in the DataTableCollection.
[Visual Basic] Private Sub TestForTableName() Dim dSet As DataSet ' Get the DataSet of a DataGrid. dSet = CType(DataGrid1.DataSource, DataSet) ' Get the DataTableCollection through the Tables property. Dim tablesCol As DataTableCollection tablesCol = dSet.Tables ' Check if the named table exists. If tablesCol.Contains("Suppliiers") Then MessageBox.Show("Table named Suppliers exists") End If End Sub [C#] private void TestForTableName() { DataSet dSet; // Get the DataSet of a DataGrid. dSet = (DataSet)DataGrid1.DataSource; // Get the DataTableCollection through the Tables property. DataTableCollection tablesCol = dSet.Tables; // Check if the named table exists. if (tablesCol.Contains("Suppliiers")) MessageBox.Show("Table named Suppliers exists"); }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET
DataTableCollection Class | DataTableCollection Members | System.Data Namespace | Item | IndexOf | Remove | CanRemove