System.Data Namespace DataColumnCollection Class
Removes the column with the specified name from the collection.
[ VB ]
Overloads Public Sub Remove ( _
ByVal name As String _
)
[ C# ]
public void Remove (
string name
);
[ C++ ]
public: void Remove (
String* name
);
[ JScript ]
public function Remove (
name : String
);
- name
- The name of the column to remove.
Use this overloaded version of the Remove method to remove the DataColumn with the specified name in the DataColumnCollection.
To remove a column at a specified index, use the RemoveAt method. You can also use the Clear method to remove all members of the collection at once.
The CollectionChanged event occurs when a column is successfully removed 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.
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 DataColumnCollection.Remove Overload List Contains