This documentation is archived and is not being maintained.

DataColumn Constructor (String, Type)

.NET Framework 1.1

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

[Visual Basic]
Public Sub New( _
   ByVal columnName As String, _
   ByVal dataType As Type _
public DataColumn(
   string columnName,
 Type dataType
public: DataColumn(
   String* columnName,
 Type* dataType
public function DataColumn(
   columnName : String,
 dataType : Type


A string that represents the name of the column to be created. If set to a null reference (Nothing in Visual Basic) or an empty string (""), a default name will be given when added to the columns collection.
A supported DataType.


Exception Type Condition
ArgumentNullException No dataType was specified.


[Visual Basic, C#, C++] The following example creates a new DataColumn with a specified ColumnName and DataType.

[Visual Basic] 

 Private Sub AddDataColumn(ByVal myTable As DataTable)
    Dim myColumn As DataColumn 
    Dim myType As System.Type
    myType = System.Type.GetType("System.Int32")
    myColumn = New DataColumn("id", myType)
    ' Set various properties.
    With myColumn
       .AutoIncrement = True
       .AutoIncrementSeed = 1
       .AutoIncrementStep = 1
       .ReadOnly = True
     End With
    ' Add to Columns collection.
 End Sub

private void AddDataColumn(DataTable myTable){
    System.Type myDataType;
    myDataType = System.Type.GetType("System.Int32");
    DataColumn myColumn = new DataColumn("id", myDataType);
    // Set various properties.
    myColumn.AutoIncrement = true;
    myColumn.AutoIncrementSeed = 1;
    myColumn.AutoIncrementStep = 1;
    myColumn.ReadOnly = true;
    // Add to Columns collection.

void AddDataColumn(DataTable* myTable){
    System::Type* myDataType;
    myDataType = System::Type::GetType(S"System.Int32");
    DataColumn* myColumn = new DataColumn(S"id", myDataType);
    // Set various properties.
    myColumn->AutoIncrement = true;
    myColumn->AutoIncrementSeed = 1;
    myColumn->AutoIncrementStep = 1;
    myColumn->ReadOnly = true;
    // Add to Columns collection.

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataColumn Class | DataColumn Members | System.Data Namespace | DataColumn Constructor Overload List | DefaultValue | ColumnName | Caption | DataTable | DataType