System.Data Namespace DataColumn Class
Inititalizes a new instance of the DataColumn class using the specified column name and data type.
[ VB ]
Overloads Public Sub New ( _
ByVal columnName As String, _
ByVal dataType As Type _
)
[ C# ]
public DataColumn (
string columnName,
Type dataType
);
[ C++ ]
public: DataColumn (
String* columnName,
Type* dataType
);
[ JScript ]
public function DataColumn (
columnName : String,
dataType : Type
);
- 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.
The following example initializes a new DataColumn with a specified ColumnName and DataType.
private void AddDataColumn ( ) {
System.Type dtype = new System.Type.GetType ( "System.Int32" );
DataColumn myColumn = new DataColumn ( "id", dtype );
// set various properties.
myColumn.Unique = true;
myColumn.AutoIncrement = true;
myColumn.AutoIncrementSeed = 1;
myColumn.AutoIncrementStep = 1;
myColumn.ReadOnly = true;
// add to Columns collection.
myTable.Columns.Add ( myColumn );
}
Private Sub AddDataColumn ( )
Dim dtype As New System.Type.GetType ( "System.Int32" )
Dim myColumn As New DataColumn ( "id", dtype )
' set various properties.
With myColumn
.Unique = True
.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 DefaultValue ColumnName Caption DataTable DataType