This documentation is archived and is not being maintained.

DataColumnCollection.Add Method ()

.NET Framework 1.1

Creates and adds a DataColumn object to the DataColumnCollection.

[Visual Basic]
Overloads Public Overridable Function Add() As DataColumn
public virtual DataColumn Add();
public: virtual DataColumn* Add();
public function Add() : DataColumn;

Return Value

The newly created DataColumn.


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.


[Visual Basic] The following example creates and adds a new DataColumn to the DataColumnCollection of a DataTable.

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

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataColumnCollection Class | DataColumnCollection Members | System.Data Namespace | DataColumnCollection.Add Overload List | ColumnName | Contains | DataType | Expression