DataColumnCollection.Contains(String) DataColumnCollection.Contains(String) DataColumnCollection.Contains(String) DataColumnCollection.Contains(String) Method


Checks whether the collection contains a column with the specified name.

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


String String String String

The ColumnName of the column to look for.


true if a column exists with this name; otherwise, false.


The following example uses the Contains method and the CanRemove method to determine whether the column can be removed. If so, the column is removed.

   private void RemoveColumn(string columnName, DataTable table)
       DataColumnCollection columns = table.Columns;

       if (columns.Contains(columnName))
           if (columns.CanRemove(columns[columnName]))
Private Sub RemoveColumn(columnName As String, table As DataTable)
    Dim columns As DataColumnCollection = table.Columns

    If columns.Contains(columnName) Then 
        If columns.CanRemove(columns(columnName)) Then 
        End If
    End If
End Sub


Use the Contains method to confirm the existence of a column before you perform additional operations on the column. The method returns false when two or more columns have the same name but different namespaces. The call does not succeed if there is any ambiguity when matching a column name to exactly one column.

Applies to

See also