Documentation for this section has not yet been entered.
Setting the DataColumn.DataType value is very important to guaranteeing the correct creation and updating of data in a data source.
The DataColumn.DataType property supports the following base .NET Framework data types:
as well as the following array type:
Byte[]
An exception is generated when changing this property after the column has begun storing data.
If DataColumn.AutoIncrement is set to true before setting the DataColumn.DataType property, and you try to set the type to anything except an integer type, an exception is generated.
A column of data type Byte[] requires special treatment in certain cases since, unlike the base .NET Framework data types, it is a reference data type. If a column of data type Byte[] is used as a DataTable.PrimaryKey, or as a DataView.Sort or DataView.RowFilter key for a System.Data.DataView, any change to the column value must involve assigning the Byte[] column value to a separately instantiated Byte[] object. This assignment is required to trigger the update of the internal indexes used by sorting, filtering, and primary key operations. This is illustrated by the following example:
Example
byte[] columnValue = (byte[])myDataTable.Rows[0][0]; byte[] newValue = (byte[])columnValue.Clone(); newValue[1] = 2; myDataTable.Rows[0][0] = newValue;
Although it is possible to define a column as data type other than the base .NET Framework data types and Byte[], such a column will be treated as a user-defined type, subject to the following usage restrictions. (For more information on user-defined types, see Creating and Using User-Defined Types.)
The column cannot be part of a DataView.RowFilter or DataTable.Select expression.
If the column is used as a DataTable.PrimaryKey, or as a DataView.Sort or for a System.Data.DataView, it must be treated as an immutable field; the column data must not be changed once it has been added to the table.
Its DataColumn.ColumnMapping can be only set to MappingType.Element.
The class that implements the column’s data type must be must be marked with the SerializableAttribute, and if necessary implement the System.Runtime.Serialization.ISerializable or System.Xml.Serialization.IXmlSerializable interface.
Support for change tracking is limited. To utilize the System.Data.DataTable class’s change tracking mechanism, the class that implements the column’s data type must either implement the System.ComponentModel.IChangeTracking interface, or take over the responsibility for informing the System.Data.DataRow when the column value has been modified, either by calling DataRow.SetModified on the row or by assigning the column value object to a separately instantiated column value object.