asp.net.ph

DataColumnCollection.Add Method ( DataColumn )

System.Data Namespace   DataColumnCollection Class


Initializes and adds a specified DataColumn object to the columns collection.

[ VB ]
Overloads Public Sub Add ( _
   ByVal column As DataColumn _
)

[ C# ]
public void Add (
   DataColumn column
);

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

[ JScript ]
public function Add (
   column : DataColumn
);

Parameters

column
The DataColumn to add.

Exceptions


Exception Type Condition
ArgumentNullException The column parameter is a null reference.
ArgumentException The column already belongs to this collection, or to another collection.
DuplicateNameException The collection already has a column with the same name ( the comparison is not case-sensitive ).
InvalidExpressionException The expression is invalid. See the Expression property for details on creating expressions.

Remarks

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 New DataColumn ( )
   With myCol
      .ColumnName = "Total"
      .DataType = System.Type.GetType ( "System.Decimal" )
      .Expression = "UnitPrice * Quantity"
      .ReadOnly = True
      .Unique = False
   End With
   cols.Add ( myCol )
End Sub
See Also

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