Conversions Involving Strings

Conversions Involving Strings

The following formats are used for conversions to and from strings. Only nontrivial formats are listed. Converting a string to a nonstring type may fail for some providers if the string contains trailing blanks.

Type indicator



When strings are converted to and from binary data, each byte of binary data is represented as two ASCII characters. These characters are the ASCII character representation of the number in its hexadecimal form. For example, the string value "f222" is converted to 0xf2 0x22, and the value 0x01 0x01 is converted to the string "0101".




"True" and "False"


As in Automation, this may be localized based on provider-specific settings. For example, for the "English(United States)" default setting, this would typically be the following:

"mm/dd/yy hh:mm:ss {AM|PM}"

To control how this is localized, consumers should bind as DBTYPE_DATE or DBTYPE_VARIANT and do their own conversions.


As specified by ISO:



As specified by ISO:



As specified by ISO:

"yyyy-mm-dd hh:mm:ss.f..."

where "f..." is fractions of a second. (Up to nine digits may be used.)


"yyyyy-mm-dd hh:mm:ss.fff" where fff is 0–999. Up to 3 digits may be used. The format is the same as SYSTEMTIME. Valid filetime value is 0x0000000000000000-0x7FFFFFFFFFFFFFFF, which is 01601-01-01 00:00:000-30828-09-14 02:24:05.477.


As represented in the registry:


where x is a hexadecimal digit.



Conversions done to/from these types do not use regional settings


Conversion between strings of different locale IDs (LCIDs) is not supported. Conversion between ANSI and Unicode strings of the same LCID are required.

In converting a Unicode string to ANSI, information may be lost because the Unicode range is greater. Lost characters are represented in the ANSI string by a special character, and the conversion is considered to be a truncation.

When mixing character sets, conversion to Unicode is the preferred solution. If conversion to ANSI is needed to use ANSI strings with the user interface and the LCID of the user interface is different from the LCID of some columns, the consumer is responsible for the conversion. The LCID of a column is returned in the DBCOLUMN_COLLATING_SEQUENCE column returned by IColumnsRowset::GetColumnsRowset.

When DBTYPE_HCHAPTER is converted to DBTYPE_WSTR, the characters are the ASCII representation of the number in its hexadecimal form. For example, 0xf2220101 is converted to the string "f2220101".

When DBTYPE_WSTR is converted to DBTYPE_HCHAPTER, each byte of binary data represents two ASCII characters. For example, "f2220101" becomes 0xf2220101, and "f222" becomes 0xf222. The conversion will fail if the value does not appear to represent a valid HCHAPTER or if truncation would occur.

© 2016 Microsoft