Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

DataColumnCollection Class

Represents a collection of DataColumn objects for a DataTable.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)
public sealed class DataColumnCollection : InternalDataCollectionBase

The DataColumnCollection type exposes the following members.

  NameDescription
Public propertySupported by the XNA FrameworkCountGets the total number of elements in a collection. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkIsReadOnlyGets a value that indicates whether the InternalDataCollectionBase is read-only. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkIsSynchronizedGets a value that indicates whether the InternalDataCollectionBase is synchonized. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkItem[Int32]Gets the DataColumn from the collection at the specified index.
Public propertySupported by the XNA FrameworkItem[String]Gets the DataColumn from the collection with the specified name.
Protected propertySupported by the XNA FrameworkListGets the items of the collection as a list. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkSyncRootGets an object that can be used to synchronize the collection. (Inherited from InternalDataCollectionBase.)
Top
  NameDescription
Public methodSupported by the XNA FrameworkAdd()Creates and adds a DataColumn object to the DataColumnCollection.
Public methodSupported by the XNA FrameworkAdd(DataColumn)Creates and adds the specified DataColumn object to the DataColumnCollection.
Public methodSupported by the XNA FrameworkAdd(String)Creates and adds a DataColumn object that has the specified name to the DataColumnCollection.
Public methodSupported by the XNA FrameworkAdd(String, Type)Creates and adds a DataColumn object that has the specified name and type to the DataColumnCollection.
Public methodSupported by the XNA FrameworkAdd(String, Type, String)Creates and adds a DataColumn object that has the specified name, type, and expression to the DataColumnCollection.
Public methodSupported by the XNA FrameworkAddRangeCopies the elements of the specified DataColumn array to the end of the collection.
Public methodSupported by the XNA FrameworkCanRemoveChecks whether a specific column can be removed from the collection.
Public methodSupported by the XNA FrameworkClearClears the collection of any columns.
Public methodSupported by the XNA FrameworkContainsChecks whether the collection contains a column with the specified name.
Public methodSupported by the XNA FrameworkCopyTo(Array, Int32)Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index. (Inherited from InternalDataCollectionBase.)
Public methodSupported by the XNA FrameworkCopyTo(DataColumn[], Int32)Copies the entire collection into an existing array, starting at a specified index within the array.
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetEnumeratorGets an IEnumerator for the collection. (Inherited from InternalDataCollectionBase.)
Public methodSupported by the XNA FrameworkGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkIndexOf(DataColumn)Gets the index of a column specified by name.
Public methodSupported by the XNA FrameworkIndexOf(String)Gets the index of the column with the specific name (the name is not case sensitive).
Protected methodSupported by the XNA FrameworkMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkRemove(DataColumn)Removes the specified DataColumn object from the collection.
Public methodSupported by the XNA FrameworkRemove(String)Removes the DataColumn object that has the specified name from the collection.
Public methodSupported by the XNA FrameworkRemoveAtRemoves the column at the specified index from the collection.
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Public eventSupported by the XNA FrameworkCollectionChangedOccurs when the columns collection changes, either by adding or removing a column.
Top

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.

The following example iterates through a collection of DataColumn objects and prints various properties of each column in the collection.


private void PrintDataTableColumnInfo(DataTable table)
{
    // Use a DataTable object's DataColumnCollection.
    DataColumnCollection columns = table.Columns;

    // Print the ColumnName and DataType for each column.
    foreach(DataColumn column in columns)
    {
        Console.WriteLine(column.ColumnName);
        Console.WriteLine(column.DataType);
    }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.