This documentation is archived and is not being maintained.

DataColumn Constructor (String, Type, String)

.NET Framework 1.1

Initializes a new instance of the DataColumn class using the specified name, data type, and expression.

[Visual Basic]
Public Sub New( _
   ByVal columnName As String, _
   ByVal dataType As Type, _
   ByVal expr As String _
public DataColumn(
   string columnName,
 Type dataType,
 string expr
public: DataColumn(
   String* columnName,
 Type* dataType,
 String* expr
public function DataColumn(
   columnName : String,
 dataType : Type,
 expr : String


A string that represents the name of the column to be created. If set to a null reference (Nothing in Visual Basic) or an empty string (""), a default name will be given when added to the columns collection.
A supported DataType.
The expression used to create this column. For more details, see the Expression property.


Exception Type Condition
ArgumentNullException No dataType was specified.


[Visual Basic, C#, C++] The following example creates a computed column.

[Visual Basic] 
Private Sub AddDataColumn(ByVal myTable As DataTable)
    Dim myColumn As DataColumn 
    Dim dt As System.Type
    dt = System.Type.GetType("System.Decimal")
    myColumn = New DataColumn("Tax", dt, "UnitPrice * .0862")
    ' Set various properties.
    With myColumn
       .AutoIncrement = False
       .ReadOnly = True
    End With
    ' Add to Columns collection.
 End Sub

private void AddDataColumn(DataTable myTable){
    System.Type myDataType;
    myDataType = System.Type.GetType("System.Decimal");
    /* Create the column. The name is 'Tax,' with data type Decimal,and 
       an expression ('UnitPrice * .0862) to calculate the tax.*/
    DataColumn myColumn = new DataColumn("Tax", myDataType, "UnitPrice * .0862");
    // Set various properties.
    myColumn.AutoIncrement = false;
    myColumn.ReadOnly = true;
    // Add to Columns collection.;

void AddDataColumn(DataTable* myTable){
    System::Type* myDataType;
    myDataType = System::Type::GetType(S"System.Decimal");
    /* Create the column. The name is 'Tax,' with data type Decimal,and 
       an expression ('UnitPrice * .0862) to calculate the tax.*/
    DataColumn* myColumn = new DataColumn(S"Tax", myDataType, S"UnitPrice * .0862");
    // Set various properties.
    myColumn->AutoIncrement = false;
    myColumn->ReadOnly = true;
    // Add to Columns collection.;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ 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

DataColumn Class | DataColumn Members | System.Data Namespace | DataColumn Constructor Overload List | DefaultValue | ColumnName | Caption | DataTable | DataType | Expression