Name

DataType

Synopsis

Type dataType = DataColumn.DataType;

DataColumn.DataType = dataType;

Gets or sets the data type of the column data as a .NET Framework data type.

Notes

This DataType property supports the base .NET Framework data types described in Table 24-4.

Table 24-4. NET Framework data types

Data type

Description

Boolean

A Boolean value. Instances of this type have the value true or false.

Byte

An 8-bit unsigned integer with values ranging from 0 to 255.

Char

A Unicode character with values ranging from hexadecimal 0x0000 to 0xFFFF.

DateTime

Represents dates and times with values ranging from January 1, 0001 12:00:00 midnight to December 31, 9999 11:59:50 P.M.

Decimal

A decimal number ranging from -79,228,162,514,264,337,593,543,950,335 through +79,228,162,514,264,337,593,543,950,335. The Decimal value type eliminates rounding errors in large numbers, typical in financial calculations.

Double

A double-precision 64-bit number ranging from -1.79769313486232e308 through +1.79769313486232e308. The Double type can also contain values -0, +0, PositiveInfinity, NegativeInfinity, and Not-a-Number (NaN).

Int16

A 16-bit signed integer with values ranging from -32,768 through +32,767.

Int32

A 32-bit signed integer with values ranging from -2,147,483,648 through +2,147,483,647.

Int64

A 64-bit signed integer with values ranging from -9,223,372,036,854,775,808 through +9,223,372,036,854,775,807.

SByte

An 8-bit signed integer with values ranging from -128 through +127.

Single

A single precision floating-point number with values ranging from -3.402823e38 through +3.402823e38. The Single type can also contain values -0, +0, PositiveInfinity, NegativeInfinity, and Not-a-Number (NaN).

String

An object representing an immutable series of characters.

TimeSpan

A 64-bit time interval measured in ticks.

UInt16

A 16-bit unsigned integer with values ranging from 0 to 65,535.

UInt32

A 32-bit unsigned integer with values ranging from 0 to 4,294,967,295.

UInt64

A 64-bit unsigned integer with values ranging from 0 to 184,467,440,737,095,551,615.

The value for the DataType property can also be set using the DataColumn constructor as shown in this sample:

DataColumn col = new DataColumn("MyColumn", typeof(System.String));

If the AutoIncrement property of the column is set to true, the DataType property must be set to an integer type; an ArgumentException is raised if an attempt is made to set the DataType property to a noninteger data type.

An ArgumentException is raised if the value of the DataType property is changed once there is data in the table.

The default value for this property is String.