DataType
TypedataType
= DataColumn.DataType; DataColumn.DataType =dataType
;
Gets or sets the data type of the column data as a .NET Framework data type.
The following example demonstrates how to set the data type for a column:
DataColumn col = new DataColumn(); col.DataType = typeof(Int32);
This DataType
property supports the base
.NET Framework data types described
in Table 24-4.
Data type |
Description |
Boolean |
A Boolean value. Instances of this type have the value
|
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
|
Double |
A double-precision 64-bit number ranging from -1.79769313486232e308
through +1.79769313486232e308. The |
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 |
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. |
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
.