DataColumn Constructor (String, Type, String)

DataColumn Constructor (String, Type, String)


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

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

public DataColumn(
	string columnName,
	Type dataType,
	string expr


Type: System.String

A string that represents the name of the column to be created. If set to null or an empty string (""), a default name will be specified when added to the columns collection.

Type: System.Type

A supported DataType.

Type: System.String

The expression used to create this column. For more information, see the Expression property.

Exception Condition

No dataType was specified.

The following example creates a computed column.

private void AddDataColumn(DataTable table)
    System.Type decimalType;
    decimalType = 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 column = new DataColumn("Tax", 
        decimalType, "UnitPrice * .0862");

    // Set various properties.
    column.AutoIncrement = false;
    column.ReadOnly = true;

    // Add to Columns collection.;

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft