asp.net.ph

DataColumnCollection.Add Method ( )

System.Data Namespace   DataColumnCollection Class


Initializes and adds a new DataColumn to the columns collection.

[ VB ]
Overloads Public Function Add ( ) As DataColumn

[ C# ]
public virtual DataColumn Add ( );

[ C++ ]
public: virtual DataColumn* Add ( );

[ JScript ]
public function Add ( ) : DataColumn;

Return Value

The newly created DataColumn.

Remarks

A default name ( "Column1", "Column2", etc. ) is given to the column.

If the collection is successfully changed by adding or removing columns, the CollectionChanged event occurs.

Example

The following example initializes and adds a new DataColumn to the DataColumnCollection of a DataTable using this constructor.

Private Sub AddColumn ( )
   ' get the DataColumnCollection from a table in a DataSet.
   Dim cols As DataColumnCollection = ds.Tables ( "Prices" ).Columns
   Dim myCol As DataColumn = cols.Add ( )
   With myCol
      .ColumnName = "Total"
      .DataType = System.Type.GetType ( "System.Decimal" )
      .Expression = "UnitPrice * Quantity"
      .ReadOnly = True
      .Unique = False
   End With
End Sub
See Also

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