asp.net.ph

DataColumnCollection.CanRemove Method

System.Data Namespace   DataColumnCollection Class


Checks whether a given column can be removed from the collection.

[ VB ]
Public Function CanRemove ( _
   ByVal column As DataColumn _
) As Boolean

[ C# ]
public bool CanRemove (
   DataColumn column
);

[ C++ ]
public: bool CanRemove (
   DataColumn* column
);

[ JScript ]
public function CanRemove (
   column : DataColumn
) : Boolean;

Parameters

column
A DataColumn in the collection.

Return Value

true if the column can be removed; otherwise, false.

Exceptions


Exception Type Condition
ArgumentNullException The column parameter is a null reference.
ArgumentException The column does not belong to this collection, or the column is part of a relationship, or another column's compute expression depends on this column.

Remarks

The CanRemove method performs several checks before returning a true or false including the following: whether the column exists, belongs to the table, is involved in a constraint or relation.

Use the CanRemove method before attempting to remove any column from a collection. You can also use the Contains method to determine if a particular column exists before attempting to reference it.

Example

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 ) {
   // get the DataColumnCollection from a DataTable in a DataSet.
   DataColumnCollection cols = ds.Tables [ "Orders" ].Columns;
   
   if ( cols.Contains ( "Totals" ) ) {
      if ( cols.CanRemove ( cols ( "Totals" ) ) ) {
         cols.Remove ( "Totals" );
      }
    }
}
  C# VB

See Also

DataColumnCollection Members   Contains   Remove Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph