Represents a collection of DataColumn objects for a DataTable.
Object
BaseCollection
ColumnsCollection
[Visual Basic] Public Class ColumnsCollection Inherits BaseCollection [C#] public class ColumnsCollection : BaseCollection [C++] public __gc class ColumnsCollection : public BaseCollection [JScript] public class ColumnsCollection extends BaseCollection
The ColumnsCollection is a major component of a DataTable. Accessed through the Columns property, the collection of columns defines the table's schema and thus determines what kind of data can be contained by a DataTable.
The ColumnsCollection contains is accessed through the Columns property of the DataTable.
The ColumnsCollection uses the standard collection methods, such as Add, Remove, Clear, and All. To determine the number of elements in the collection, use the Count property.
The Contains method verifies that a specified index or column name exists in the collection.
Namespace: System.Data
Assembly: System.Data.dll
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 ColumnsCollection ' Use a DataTable object's ColumnsCollection: cols = myTable.Columns ' Get all of the columns using a For Each statement: Dim col As DataColumn For Each col in cols Console.WriteLine(col.ColumnName) Console.WriteLine(col.DataType.ToString) Console.WriteLine(col.DefaultValue) Next End Sub
ColumnsCollection Members | System.Data Namespace | Columns | DataColumn | DataTable | DataRelation | DataRow | DataSet