NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

DataColumn.DataType

The type of data stored in thecolumn.

[Visual Basic]
Public Property DataType As Type
[C#]
public Type DataType {get; set;}
[C++]
public: __property Type* get_DataType();
public: __property void set_DataType(Type*);
[JScript]
public function get DataType() : Type;
public function set DataType(Type);

Property Value

A Type object that represents the column's data type.

Exceptions

Exception Type Condition
ArgumentException The column already has data stored.
ArgumentException AutoIncrement is true, but the value is set to a type a unsupported by AutoIncrement.

Remarks

Setting the DataType value is critical to ensuring the correct creation and updating of data in a DBMS.

The DataType property supports the base data types shown below:

Note   The following types are not supported by Visual Basic: DateTime, UInt16, UInt32, UInt64, and TimeSpan.

An exception is thrown when changing this property after the column has begun storing data.

If AutoIncrement is set to true before setting the DataType property, and you attempt to set the type to anything except an integer type, an exception will be thrown.

Example [Visual Basic]

The following example adds columns of several data types to a DataTable, then adds one row to the table.

[Visual Basic]

Public Function MakeDataTable() As DataTable
   Dim myTable As DataTable
   Dim row As DataRow
   Dim r As Integer
   Dim c As Integer
   myTable = New DataTable("My Table")
   myTable.Columns.Add New DataColumn("StringCol", System.Type.GetType("System.String"))
   myTable.Columns.Add New DataColumn("ByteCol", System.Type.GetType("System.Byte"))
   myTable.Columns.Add New DataColumn("Int16Col", System.Type.GetType("System.Int16"))
   myTable.Columns.Add New DataColumn("Int32Col", System.Type.GetType("System.Int32"))
   myTable.Columns.Add New DataColumn("BooleanCol", System.Type.GetType("System.Boolean"))
   myTable.Columns.Add New DataColumn("TimeSpanCol", System.Type.GetType("System.TimeSpan"))
   myTable.Columns.Add New DataColumn("DateTimeCol", System.Type.GetType("System.DateTime"))
   myTable.Columns.Add New DataColumn("CurrencyCol", System.Type.GetType("System.Currency"))
   ' Populate one row with values.
   row = myTable.NewRow
   row(0) = "Item Name"
   ' Can't do column1 because it takes a byte.
   row(2) = 32767
   row(3) = 2147483647
   row(4) = True
   row(5) = "10675199.02:48:05.477"
   row(6) = now
   row(7) = 64000
   myTable.Rows.Add row
   MakeDataTable = myTable
nd Function

See Also

DataColumn Class | DataColumn Members | System.Data Namespace | Type | GetType