asp.net.ph

DataColumnCollection.Remove Method ( String )

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
);

Parameters

name
The name of the column to remove.

Exceptions


Exception Type Condition
IndexOutOfRangeException The collection does not have a column with the specified name.

Remarks

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.

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, 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 );
   }
}
  C# VB

See Also

DataColumnCollection Members   DataColumnCollection.Remove Overload List   Contains 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