Export (0) Print
Expand All

DataColumn Constructor (String)

.NET Framework 1.1

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

[Visual Basic]
Public Sub New( _
   ByVal columnName As String _
)
[C#]
public DataColumn(
   string columnName
);
[C++]
public: DataColumn(
   String* columnName
);
[JScript]
public function DataColumn(
   columnName : String
);

Parameters

columnName
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.

Remarks

By default, the name given to a column becomes the Caption property value.

Example

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

[Visual Basic] 

 Private Sub AddDataColumn(ByVal myTable As DataTable)
    Dim myColumn As DataColumn 
    myColumn = New DataColumn("id")
    ' Set various properties.
    With myColumn
       .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#] 
private void AddDataColumn(DataTable myTable){
    DataColumn myColumn = new DataColumn("id");
    // Set various properties.
    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);
 }

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

[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.

Requirements

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 | ColumnName | Caption | DefaultValue | DataTable | DataType

Show:
© 2014 Microsoft