DataColumnCollection Class

 

Represents a collection of DataColumn objects for a DataTable.

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

System.Object
  System.Data.InternalDataCollectionBase
    System.Data.DataColumnCollection

public sealed class DataColumnCollection : InternalDataCollectionBase

NameDescription
System_CAPS_pubpropertyCount

Gets the total number of elements in a collection.(Inherited from InternalDataCollectionBase.)

System_CAPS_pubpropertyIsReadOnly

Gets a value that indicates whether the InternalDataCollectionBase is read-only.(Inherited from InternalDataCollectionBase.)

System_CAPS_pubpropertyIsSynchronized

Gets a value that indicates whether the InternalDataCollectionBase is synchonized.(Inherited from InternalDataCollectionBase.)

System_CAPS_pubpropertyItem[Int32]

Gets the DataColumn from the collection at the specified index.

System_CAPS_pubpropertyItem[String]

Gets the DataColumn from the collection with the specified name.

System_CAPS_pubpropertySyncRoot

Gets an object that can be used to synchronize the collection.(Inherited from InternalDataCollectionBase.)

NameDescription
System_CAPS_pubmethodAdd()

Creates and adds a DataColumn object to the DataColumnCollection.

System_CAPS_pubmethodAdd(DataColumn)

Creates and adds the specified DataColumn object to the DataColumnCollection.

System_CAPS_pubmethodAdd(String)

Creates and adds a DataColumn object that has the specified name to the DataColumnCollection.

System_CAPS_pubmethodAdd(String, Type)

Creates and adds a DataColumn object that has the specified name and type to the DataColumnCollection.

System_CAPS_pubmethodAdd(String, Type, String)

Creates and adds a DataColumn object that has the specified name, type, and expression to the DataColumnCollection.

System_CAPS_pubmethodAddRange(DataColumn[])

Copies the elements of the specified DataColumn array to the end of the collection.

System_CAPS_pubmethodCanRemove(DataColumn)

Checks whether a specific column can be removed from the collection.

System_CAPS_pubmethodClear()

Clears the collection of any columns.

System_CAPS_pubmethodContains(String)

Checks whether the collection contains a column with the specified name.

System_CAPS_pubmethodCopyTo(Array, Int32)

Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index.(Inherited from InternalDataCollectionBase.)

System_CAPS_pubmethodCopyTo(DataColumn[], Int32)

Copies the entire collection into an existing array, starting at a specified index within the array.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetEnumerator()

Gets an IEnumerator for the collection.(Inherited from InternalDataCollectionBase.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodIndexOf(DataColumn)

Gets the index of a column specified by name.

System_CAPS_pubmethodIndexOf(String)

Gets the index of the column with the specific name (the name is not case sensitive).

System_CAPS_pubmethodRemove(DataColumn)

Removes the specified DataColumn object from the collection.

System_CAPS_pubmethodRemove(String)

Removes the DataColumn object that has the specified name from the collection.

System_CAPS_pubmethodRemoveAt(Int32)

Removes the column at the specified index from the collection.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubeventCollectionChanged

Occurs when the columns collection changes, either by adding or removing a column.

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast<TResult>()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType<TResult>()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

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
Available since 1.1

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

Return to top
Show: