asp.net.ph

DataColumn Constructor

System.Data Namespace   DataColumn Class


Initializes a new instance of the DataColumn class.

Overload List

1. Initializes a new instance of a DataColumn class.

2. Inititalizes a new instance of the DataColumn class using the specified column name.

3. Inititalizes a new instance of the DataColumn class using the specified column name and data type.

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

5. Initializes a new instance of the DataColumn class using the specified name, data type, expression, and value that determines whether the column is an attribute.


Example

The following example constructs a computed column.

NOTE: This example uses one of the overloaded versions of the DataColumn constructor. For other examples that may be available, see the individual overload topics.

private void CreateComputedColumn ( ) {
   System.Type dtype = new System.Type.GetType ( "System.Decimal" );

   // the expression multiplies the "Price" column value
   // by the "Quantity" to create the "Total" column.
   string strExpr = "Price * Quantity";

   // create the column, setting the type to Attribute.
   DataColumn myColumn = new DataColumn ( "Total", dtype, 
      strExpr, MappingType.Attribute );

   // set various properties.
   myColumn.Unique = true;
   myColumn.AutoIncrement = false;
   myColumn.ReadOnly = true;

   // add the column to a DataTable object's to ColumnsCollection.
   myDataColumn.Tables [ "OrderDetails" ].Columns.Add ( myColumn );
}
  C# VB

See Also

DataColumn Members   Unique 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