System.Data Namespace DataColumnCollection Class
Checks whether the collection contains a column with the specified name.
[ VB ]
Overloads 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;
- name
- The name of the column.
true if a column exists with this name; otherwise, false.
Use the Contains method to confirm the existence of a column before performing further operations on the column.
The following example first uses the Contains method to determine if a particular column exists in the collection. If found, the CanRemove method tests whether the column can be removed. If so, the column is removed with the Remove method.
private void RemoveColumn ( DataSet ds, string colName ) {
// get the DataColumnCollection from a DataTable in a DataSet.
DataColumnCollection cols = ds.Tables [ "Orders" ].Columns;
if ( cols.Contains ( colName ) && cols.CanRemove ( cols [ colName ] ) ) {
cols.Remove ( colName );
}
}
Private Sub RemoveColumn ( ByVal ds As DataSet, ByVal colName As String )
' get the DataColumnCollection from a DataTable in a DataSet.
Dim cols As DataColumnCollection = ds.Tables ( "Orders" ).Columns
If cols.Contains ( colName ) And cols.CanRemove ( cols ( colName ) ) Then
cols.Remove ( colName )
End If
End Sub |
|
C# |
VB |
DataColumnCollection Members CanRemove IndexOf