System.Data Namespace DataColumn Class
Initializes a new instance of the DataColumn class using the specified name, data type, and expression.
[ VB ]
Overloads Public Sub New ( _
ByVal columnName As String, _
ByVal dataType As Type, _
ByVal expr As String _
)
[ C# ]
public DataColumn (
string columnName,
Type dataType,
string expr
);
[ C++ ]
public: DataColumn (
String* columnName,
Type* dataType,
String* expr
);
[ JScript ]
public function DataColumn (
columnName : String,
dataType : Type,
expr : String
);
- columnName
- A string that represents the name of the column to be created. If set to a null reference or an empty string ( "" ), a default name will be given when added to the columns collection.
- dataType
- A supported DataType.
- expr
- The expression used to create this column. For more details, see the Expression property.
The following example initializes a computed column.
private void AddDataColumn ( ) {
System.Type dt new 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", dt, "UnitPrice * .0862" );
// set various properties.
myColumn.Unique = true;
myColumn.AutoIncrement = false;
myColumn.ReadOnly = true;
// add to Columns collection.;
myTable.Columns.Add ( myColumn );
}
Private Sub AddDataColumn ( )
Dim dt As New 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.
Dim myColumn As New DataColumn ( "Tax", dt, "UnitPrice * .0862" )
' set various properties.
With myColumn
.Unique = False
.AutoIncrement = False
.ReadOnly = True
End With
' add to Columns collection.
myTable.Columns.Add ( myColumn )
End Sub |
|
C# |
VB |
DataColumn Members DataColumn Constructor Overload List DefaultValue ColumnName Caption DataTable DataType Expression