ערוך

שתף באמצעות


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.

public:
 bool Contains(System::String ^ name);
public bool Contains (string? name);
public bool Contains (string name);
member this.Contains : string -> bool
Public Function Contains (name As String) As Boolean

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.

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

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.

Note

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

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.

public:
 bool Contains(System::String ^ name, System::String ^ tableNamespace);
public bool Contains (string name, string tableNamespace);
member this.Contains : string * string -> bool
Public Function Contains (name As String, tableNamespace As String) As Boolean

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.

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

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

Note

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