System.Data Namespace DataColumnCollection Class
Removes a column from the collection.
1. Removes the specified DataColumn object from the collection.
2. Removes the column with the specified name from the collection.
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.
NOTE: This example shows how to use one of the overloaded versions of Remove. For other examples that may be available, see the individual overload topics.
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