NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

ColumnsCollection.CanRemove

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

[Visual Basic]
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 no exception occurs and the column can be removed; otherwise, false.

Exceptions

Exception Type Condition
ArgumentNullException The column parameter is a null reference (in Visual Basic Nothing).
ArgumentException The column doesn't 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 [Visual Basic]

The following example first uses the Contains method to determine if a particular column is found 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.

[Visual Basic]

Dim cols As ColumnsCollection
' Get the ColumnsCollection from a DataTable in a DataSet.
cols = DataSet1.Tables("Orders").Columns

If cols.Contains(2) Then 
   If cols.CanRemove(cols(2)) Then
      cols.Remove 2
   End If
End If

See Also

ColumnsCollection Class | ColumnsCollection Members | System.Data Namespace | Contains | Remove