This documentation is archived and is not being maintained.

DataTable.Columns Property

Gets the collection of columns that belong to this table.

[Visual Basic]
Public ReadOnly Property Columns As DataColumnCollection
public DataColumnCollection Columns {get;}
public: __property DataColumnCollection* get_Columns();
public function get Columns() : DataColumnCollection;

Property Value

A DataColumnCollection that contains the collection of DataColumn objects for the table; otherwise a null value if no DataColumn objects exist.


The DataColumnCollection determines the schema of a table by defining the data type of each column.


[Visual Basic, C#, C++] The following example prints each value of each row in a table using the Columns property.

[Visual Basic] 
Private Sub PrintValues(ByVal myTable As DataTable)
    Dim myRow As DataRow
    Dim myColumn As DataColumn
    For Each myRow in myTable.Rows
       For Each myColumn In myTable.Columns
 End Sub

private void PrintValues(DataTable myTable){
    foreach(DataRow myRow in myTable.Rows){
       foreach(DataColumn myCol in myTable.Columns){

void PrintValues(DataTable* myTable){
    System::Collections::IEnumerator* myEnum = myTable->Rows->GetEnumerator();
    while (myEnum->MoveNext())
       DataRow* myRow = __try_cast<DataRow*>(myEnum->Current);
       System::Collections::IEnumerator* myEnum1 = myTable->Columns->GetEnumerator();
       while (myEnum1->MoveNext())
          DataColumn* myCol = __try_cast<DataColumn*>(myEnum1->Current);

[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

DataTable Class | DataTable Members | System.Data Namespace | DataColumnCollection | DataColumn