DataColumn.ColumnName Property

Definition

DataColumnCollection의 열 이름을 가져오거나 설정합니다.Gets or sets the name of the column in the DataColumnCollection.

public:
 property System::String ^ ColumnName { System::String ^ get(); void set(System::String ^ value); };
public string ColumnName { get; set; }
[System.Data.DataSysDescription("DataColumnColumnNameDescr")]
public string ColumnName { get; set; }
member this.ColumnName : string with get, set
Public Property ColumnName As String

Property Value

String

열 이름입니다.The name of the column.

Attributes

Exceptions

속성이 null 또는 빈 문자열로 설정되어 있고 열이 컬렉션에 속한 경우The property is set to null or an empty string and the column belongs to a collection.

같은 이름의 열 컬렉션에 이미 있습니다.A column with the same name already exists in the collection. 이름 비교는 대/소문자 구분 되지 않습니다.The name comparison is not case sensitive.

Examples

다음 예에서는 DataSet의 모든 테이블에 있는 모든 열에 대 한 ColumnName를 가져옵니다.The following examples gets the ColumnName for every column in every table in a DataSet. 또한이 예제에서는 새 ColumnName를 사용 하 여 DataColumn을 만드는 방법을 보여 줍니다.The example also shows how to create a DataColumn with a new ColumnName.

private void PrintColumnNames(DataSet dataSet)
{
    // For each DataTable, print the ColumnName.
    foreach(DataTable table in dataSet.Tables)
    {
        foreach(DataColumn column in table.Columns)
        {
            Console.WriteLine(column.ColumnName);
        }
    }
}

private void AddColumn(DataTable table)
{
    DataColumn column;
    column = new DataColumn();
    column.ColumnName = "SupplierID";
    column.DataType = System.Type.GetType("System.String");
    column.Unique = true;
    column.AutoIncrement = false;
    column.Caption = "SupplierID";
    column.ReadOnly = false;

    // Add the column to the table's columns collection.
    table.Columns.Add(column);
}
Private Sub PrintColumnNames(dataSet As DataSet)
    Dim table As DataTable
    Dim column As DataColumn 

    ' For each DataTable, print the ColumnName.
    For Each table in dataSet.Tables
        For Each column in table.Columns
        Console.WriteLine(column.ColumnName)
        Next
    Next
End Sub

Private Sub AddColumn(table As DataTable)
    Dim column As DataColumn
    column = New DataColumn()

    With column
        .ColumnName = "SupplierID"
        .DataType = System.Type.GetType("System.String")
        .Unique = True
        .AutoIncrement = False
        .Caption = "SupplierID"
        .ReadOnly = False
    End With

    ' Add the column to the table's columns collection.
    table.Columns.Add(column)
End Sub

Remarks

DataColumn 만들어지면 ColumnName 값이 없습니다.When a DataColumn is created, it has no ColumnName value. 그러나 DataColumnDataTable 개체의 DataColumnCollection에 추가 하면 기본 이름 ("Column1", "Column2" 등)이 지정 됩니다.However, when the DataColumn is added to a DataColumnCollection for a DataTable object, it is given a default name ("Column1", "Column2", and so on).

기본적으로 Caption 값은 ColumnName 값으로 설정 됩니다.By default, the Caption value is set to the ColumnName value.

Applies to

See also