asp.net.ph

DataColumnCollection.Contains Method ( String )

System.Data Namespace   DataColumnCollection Class


Checks whether the collection contains a column with the specified name.

[ VB ]
Overloads Public Function Contains ( _
   ByVal name As String _
) As Boolean

[ C# ]
public bool Contains (
   string name
);

[ C++ ]
public: bool Contains (
   String* name
);

[ JScript ]
public function Contains (
   name : String
) : Boolean;

Parameters

name
The name of the column.

Return Value

true if a column exists with this name; otherwise, false.

Remarks

Use the Contains method to confirm the existence of a column before performing further operations on the column.

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   CanRemove   IndexOf 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