DB2 Version 9.7 for Linux, UNIX, and Windows

SQL data type representation in ADO.NET database applications

ADO.NET database applications can reference DB2 SQL data type values as parameter values to be used as part of SQL statement execution and as variables, however the appropriate IBM® Data Server Provider for .NET data type values and .NET Framework data type values must be used to ensure that there is no truncation or loss of data when accessing or retrieving the values.

For specifying parameter values to be used as part of a SQL statement to be executed, IBM Data Server Provider for .NET objects must be used. The DB2Parameter object is used to represent a parameter to be added to a DB2Command object which represents a SQL statement. When specifying the data type value for the parameter, the IBM Data Server Provider for .NET data type values available in the IBM.Data.DB2Types namespace must be used. The IBM.Data.DB2Types namespace provides classes and structures to represent each of the supported DB2 SQL data types.

For local variables that might temporarily hold SQL data type values, appropriate IBM Data Server Provider for .NET data types, as defined in the IBM.Data.DB2Types Namespace, must be used.

The following table shows mappings between DB2Type data types, DB2® data types, Informix® data types, Microsoft .NET Framework types, and DB2Types classes and structures.

Category DB2Types Classes and Structures DB2Type Data Type DB2 Data Type Informix Data Type .NET Data Type
Binary data DB2Binary Binary CHAR FOR BIT DATA   Byte[]
DB2Binary Binary3 BINARY   Byte[]
DB2Binary VarBinary3 VARBINARY   Byte[]
DB2Binary LongVarBinary1 LONG VARCHAR FOR BIT DATA   Byte[]
Character data DB2String Char CHAR CHAR String
DB2String VarChar VARCHAR VARCHAR String
DB2String LongVarChar1 LONG VARCHAR LVARCHAR String
Graphic data DB2String Graphic GRAPHIC   String
DB2String VarGraphic VARGRAPHIC   String
DB2String LongVarGraphic1 LONG VARGRAPHIC   String
LOB data DB2Clob Clob CLOB CLOB, TEXT String
DB2Blob Blob BLOB BLOB, BYTE Byte[]
DB2Clob DbClob DBCLOB   String
Numeric data DB2Int16 SmallInt SMALLINT BOOLEAN, SMALLINT Int16
DB2Int32 Integer INT INTEGER, INT, SERIAL Int32
DB2Int64 BigInt, BigSerial BIGINT BIGINT, BIGSERIAL, INT8, SERIAL8 Int64
DB2Real, DB2Real370 Real REAL REAL, SMALLFLOAT Single
DB2Double Double DOUBLE PRECISION DECIMAL (≤ 29), DOUBLE PRECISION Double
DB2Double Float FLOAT DECIMAL (32), FLOAT Double
DB2Decimal Decimal DECIMAL MONEY Decimal
DB2DecimalFloat DecimalFloat DECFLOAT(16|34)14   Decimal
DB2Decimal Numeric DECIMAL DECIMAL (≤ 29), NUMERIC Decimal
Date/Time data DB2Date Date DATE DATETIME (date precision)

DateTime

String5

DB2Time Time TIME DATETIME (time precision)

TimeSpan

String5

DB2TimeStamp Timestamp TIMESTAMP DATETIME (time and date precision)

DateTime

String5

DB2TimeStamp Offset TimestampWith TimeZone TIMESTAMP WITH TIME ZONE N/A

DateTimeOffset

String5

Row ID data DB2RowId RowId ROWID   Byte[]
XML data DB2Xml Xml2 XML   Byte[]
1 These data types are not supported as parameters in DB2 .NET common language runtime routines.
2 A DB2ParameterClass.ParameterName property of the type DB2Type.Xml can accept variables of the following types: String, byte[], DB2Xml, and XmlReader.
3 These data types are applicable only to DB2 for z/OS® and DB2 for i V6R1 and later.
4 This data type is only supported for DB2 for z/OS Version 9 and later releases and for DB2 for Linux, UNIX, and Windows Version 9.5 and later releases.
5 Date and Time objects can be timestamp string literals. Timestamp objects can be date string literals