Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
DataColumnCollection Class
Collapse the table of content
Expand the table of content

DataColumnCollection Class

Represents a collection of DataColumn objects for a DataTable.

For a list of all members of this type, see DataColumnCollection Members.


[Visual Basic]
Public Class DataColumnCollection
   Inherits InternalDataCollectionBase
public class DataColumnCollection : InternalDataCollectionBase
public __gc class DataColumnCollection : public
class DataColumnCollection extends

Thread Safety

This type is safe for multithreaded read operations. You must synchronize any write operations.


The DataColumnCollection defines the schema of a DataTable, and determines what kind of data each DataColumn can contain. You can access the DataColumnCollection through the Columns property of the DataTable object.

The DataColumnCollection uses the Add and Remove methods to insert and delete DataColumn objects. Use the Count property to determine how many DataColumn objects are in the collection. Use the Contains method to verify whether a specified index or column name exists in the collection.


[Visual Basic, C#, C++] The following example iterates through a collection of DataColumn objects and prints various properties of each column in the collection.

[Visual Basic] 
Private Sub PrintDataTableColumnInfo(myTable As DataTable)
    Dim cols As DataColumnCollection
    ' Use a DataTable object's DataColumnCollection.
    cols = myTable.Columns
    ' Print the ColumnName and DataType for each column.
    Dim col As DataColumn
    For Each col in cols
 End Sub

private void PrintDataTableColumnInfo(DataTable myTable){
    DataColumnCollection cols;
    // Use a DataTable object's DataColumnCollection.
    cols = myTable.Columns;
    // Print the ColumnName and DataType for each column.
    foreach(DataColumn col in cols){

void PrintDataTableColumnInfo(DataTable* myTable){
   DataColumnCollection* cols;
   // Use a DataTable object's DataColumnCollection.
   cols = myTable->Columns;
   // Print the ColumnName and DataType for each column.
   System::Collections::IEnumerator* myEnum = cols->GetEnumerator();
   while (myEnum->MoveNext())
      DataColumn* col = __try_cast<DataColumn*>(myEnum->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.


Namespace: System.Data

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

Assembly: System.Data (in System.Data.dll)

See Also

DataColumnCollection Members | System.Data Namespace | Columns | DataColumn | DataTable | DataRelation | DataRow | DataSet

© 2015 Microsoft