DataColumn.DataType プロパティ
アセンブリ: System.Data (system.data.dll 内)

列のデータ型を表す Type オブジェクト。


DataType 値の設定は、データ ソース内のデータを正しく作成および更新できるようにするために重要です。
DataType プロパティは、次に示す基本 .NET Framework データ型をサポートします。
-
Int16
-
Int32
-
Int64
-
SByte
-
TimeSpan
-
UInt16
-
UInt32
-
UInt64
-
Byte[]
列へのデータの格納が開始された後でこのプロパティを変更すると、例外が生成されます。
DataType プロパティを設定する前に AutoIncrement を true に設定し、整数型以外の型に設定しようとすると、例外が生成されます。
![]() |
---|
Byte[] データ型の列で、特別な処理を必要とする場合があります。なぜなら、このデータ型は、基本 .NET Framework データ型とは異なり参照データ型だからです。Byte[] データ型の列が PrimaryKey として使用されている場合、または DataView の Sort または RowFilter キーとして使用されている場合、列値を変更する際に、Byte[] 列値を別個にインスタンス化された Byte[] オブジェクトに割り当てる必要があります。この割り当ては、並べ替え操作、フィルタ操作、および主キー操作で使用される内部インデックスの更新を発生させるために必要です。次の例にこの操作を示します。 |
byte[] columnValue = (byte[])myDataTable.Rows[0][0]; byte[] newValue = (byte[])columnValue.Clone(); newValue[1] = 2; myDataTable.Rows[0][0] = newValue;
![]() |
---|
データ型を基本 .NET Framework データ型および Byte[] 以外のデータ型として定義することは可能ですが、このような列はユーザー定義型として扱われ、次の使用上の制限が適用されます。ユーザー定義型の詳細については、「ユーザー定義型の作成と使用」を参照してください。 |

データ型が異なる複数の列を DataTable に追加し、そのテーブルに 1 行を追加する例を次に示します。
Public Function MakeDataTable() As DataTable Dim myTable As DataTable Dim myNewRow As DataRow ' Create a new DataTable. myTable = New DataTable("My Table") ' Create DataColumn objects of data types. Dim colString As DataColumn = New DataColumn("StringCol") colString.DataType = System.Type.GetType("System.String") myTable.Columns.Add(colString) Dim colInt32 As DataColumn = New DataColumn("Int32Col") colInt32.DataType = System.Type.GetType("System.Int32") myTable.Columns.Add(colInt32) Dim colBoolean As DataColumn = New DataColumn("BooleanCol") colBoolean.DataType = System.Type.GetType("System.Boolean") myTable.Columns.Add(colBoolean) Dim colTimeSpan As DataColumn = New DataColumn("TimeSpanCol") colTimeSpan.DataType = System.Type.GetType("System.TimeSpan") myTable.Columns.Add(colTimeSpan) Dim colDateTime As DataColumn = New DataColumn("DateTimeCol") colDateTime.DataType = System.Type.GetType("System.DateTime") myTable.Columns.Add(colDateTime) Dim colDecimal As DataColumn = New DataColumn("DecimalCol") colDecimal.DataType = System.Type.GetType("System.Decimal") myTable.Columns.Add(colDecimal) ' Populate one row with values. myNewRow = myTable.NewRow() myNewRow("StringCol") = "Item Name" myNewRow("Int32Col") = 2147483647 myNewRow("BooleanCol") = True myNewRow("TimeSpanCol") = New TimeSpan(10,22,10,15,100) myNewRow("DateTimeCol") = System.DateTime.Today myNewRow("DecimalCol") = 64.0021 myTable.Rows.Add(myNewRow) MakeDataTable = myTable End Function
public DataTable MakeDataTable(){ DataTable myTable; DataRow myNewRow; // Create a new DataTable. myTable = new DataTable("My Table"); // Create DataColumn objects of data types. DataColumn colString = new DataColumn("StringCol"); colString.DataType = System.Type.GetType("System.String"); myTable.Columns.Add(colString); DataColumn colInt32 = new DataColumn("Int32Col"); colInt32.DataType = System.Type.GetType("System.Int32"); myTable.Columns.Add(colInt32); DataColumn colBoolean = new DataColumn("BooleanCol"); colBoolean.DataType = System.Type.GetType("System.Boolean"); myTable.Columns.Add(colBoolean); DataColumn colTimeSpan = new DataColumn("TimeSpanCol"); colTimeSpan.DataType = System.Type.GetType("System.TimeSpan"); myTable.Columns.Add(colTimeSpan); DataColumn colDateTime = new DataColumn("DateTimeCol"); colDateTime.DataType = System.Type.GetType("System.DateTime"); myTable.Columns.Add(colDateTime); DataColumn colDecimal = new DataColumn("DecimalCol"); colDecimal.DataType = System.Type.GetType("System.Decimal"); myTable.Columns.Add(colDecimal); // Populate one row with values. myNewRow = myTable.NewRow(); myNewRow["StringCol"] = "Item Name"; myNewRow["Int32Col"] = 2147483647; myNewRow["BooleanCol"] = true; myNewRow["TimeSpanCol"] = new TimeSpan(10,22,10 ,15,100); myNewRow["DateTimeCol"] = System.DateTime.Today; myNewRow["DecimalCol"] = 64.0021; myTable.Rows.Add(myNewRow); return myTable; }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDataColumn.DataType プロパティを検索する場合は、下記のリンクをクリックしてください。

- DataColumn.DataType プロパティのページへのリンク