System.Data Namespace DataColumn Class
Initializes a new instance of the DataColumn class.
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.
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 );
}
Private Sub CreateComputedColumn ( )
Dim dtype As New System.Type.GetType ( "System.Decimal" )
' the expression multiplies the "Price" column value
' by the "Quantity" to create the "Total" column.
Dim strExpr As String = "Price * Quantity"
' create the column, setting the type to Attribute.
Dim myColumn As 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 ColumnsCollection.
myDataColumn.Tables ( "OrderDetails" ).Columns.Add ( myColumn )
End Sub |
|
C# |
VB |
DataColumn Members Unique
|
|