asp.net.ph

DataColumnCollection.Add Method ( String )

System.Data Namespace   DataColumnCollection Class


Initializes and adds a DataColumn with the specified name to the columns collection.

[ VB ]
Overloads Public Function Add ( _
   ByVal columnName As String _
) As DataColumn

[ C# ]
public virtual DataColumn Add (
   string columnName
);

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

[ JScript ]
public function Add (
   columnName : String
) : DataColumn;

Parameters

columnName
The name of the column.

Return Value

The newly created DataColumn.

Exceptions


Exception Type Condition
DuplicateNameException The collection already has a column with the same name ( the comparison is not case-sensitive ).

Remarks

By default, the column's DataType is string.

If a null reference or an empty string ( "" ) is passed in for the name, a default name ( "Column1", "Column2", etc. ) is given to the column.

Use the Contains method to determine whether a column with the proposed name already exists in the collection.

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 ( "Total" )
   With myCol
      .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   ColumnName 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