.NET Framework Class Library  

DataTable.Columns Property

Gets the collection of columns that belong to this table.

[Visual Basic]
Public ReadOnly Property Columns As DataColumnCollection
[C#]
public DataColumnCollection Columns {get;}
[C++]
public: __property DataColumnCollection* get_Columns();
[JScript]
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.

Remarks

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

Example

[Visual Basic, 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
          Console.WriteLine(myRow(myColumn))
       Next
    Next
 End Sub

[C#] 
private void PrintValues(DataTable myTable){
    foreach(DataRow myRow in myTable.Rows){
       foreach(DataColumn myCol in myTable.Columns){
          Console.WriteLine(myRow[myCol]);
       }
    }
 }

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic 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 - Windows CE .NET

See Also

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