System.Data Namespace DataColumn Class
Initializes a new instance of a DataColumn class.
[ VB ]
Public Sub New ( )
[ C# ]
public DataColumn ( );
[ C++ ]
public: DataColumn ( );
[ JScript ]
public function DataColumn ( );
When created, a new DataColumn object has no default ColumnName or Caption. When added to a DataColumnCollection, however, a default name ( "Column1", "Column2", and so on ) is given to the column.
The following example initializes a new DataColumn using this constructor, sets various properties, and adds it to a DataTable object's DataColumnCollection.
private void AddDataColumn ( DataTable myTable ) {
DataColumn myColumn = new DataColumn ( );
// set various properties.
myColumn.ColumnName = "id";
myColumn.DataType = System.Type.GetType ( "System.Int32" );
myColumn.AutoIncrement = true;
myColumn.AutoIncrementSeed = 1;
myColumn.AutoIncrementStep = 1;
myColumn.ReadOnly = true;
// add to Columns collection.
myTable.Columns.Add ( myColumn );
}
Private Sub AddDataColumn ( ByVal myTable As DataTable )
Dim myColumn As New DataColumn ( )
' set various properties.
With myColumn
.ColumnName = "id"
.DataType = System.Type.GetType ( "System.Int32" )
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
.ReadOnly = True
End With
' add to Columns collection.
myTable.Columns.Add ( myColumn )
End Sub |
|
C# |
VB |
DataColumn Members DataColumn Constructor Overload List ColumnName Caption DefaultValue DataTable DataType