Export (0) Print
Expand All

DataColumnCollection.Add Method

Creates and adds a DataColumn object to the DataColumnCollection.

Overload List

Creates and adds a DataColumn object to the DataColumnCollection.

Supported by the .NET Compact Framework.

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

Creates and adds the specified DataColumn object to the DataColumnCollection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Add(DataColumn)
[C#] public void Add(DataColumn);
[C++] public: void Add(DataColumn*);
[JScript] public function Add(DataColumn);

Creates and adds a DataColumn object with the specified name to the DataColumnCollection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function Add(String) As DataColumn
[C#] public virtual DataColumn Add(string);
[C++] public: virtual DataColumn* Add(String*);
[JScript] public function Add(String) : DataColumn;

Creates and adds a DataColumn object with the specified name and type to the DataColumnCollection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function Add(String, Type) As DataColumn
[C#] public virtual DataColumn Add(string, Type);
[C++] public: virtual DataColumn* Add(String*, Type*);
[JScript] public function Add(String, Type) : DataColumn;

Creates and adds a DataColumn object with the specified name, type, and expression to the DataColumnCollection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function Add(String, Type, String) As DataColumn
[C#] public virtual DataColumn Add(string, Type, string);
[C++] public: virtual DataColumn* Add(String*, Type*, String*);
[JScript] public function Add(String, Type, String) : DataColumn;

Example

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

[Visual Basic] Note   This example shows how to use one of the overloaded versions of Add. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub AddColumn()
    Dim cols As DataColumnCollection
    Dim myCol As DataColumn
    ' Get the DataColumnCollection of a table in a DataSet.
    cols = DataSet1.Tables("Orders").Columns
    ' Add a new column and return it.
    myCol = cols.Add("Total", System.Type.GetType("System.Decimal"), _
       "Price + Tax")
    myCol.ReadOnly = True
    myCol.Unique = False
 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.

See Also

DataColumnCollection Class | DataColumnCollection Members | System.Data Namespace

Show:
© 2014 Microsoft