Length

The length is the length of the data in bytes. It is useful only for variable-length data. For fixed-length data, the length is always the size of the data type. For example, the length of the ANSI string "Johnson" is 7, the length of the Unicode string "Lopez" is 10 (five two-byte characters), and the length of any value stored as a two-byte integer is 2.

The length gives the length of the data as it is stored by the consumer. That is, when getting data, it is the length of the data after it is converted from the provider type to the consumer type. When setting data, it is the length of the data before it is converted from the consumer type to the provider type.

Data Length and Buffer Length

It is important not to confuse the length of the data value with the length of the buffer in which the data value is stored. For example, in the following figure, the length of the buffer is 14 and the length of the data value stored in the buffer is 10.

An example of data length in relation to buffer length

The consumer specifies the buffer length with the cbMaxLen element of the DBBINDING structure. For information about how the provider uses the buffer length in conjunction with the data length, see cbMaxLen in "DBBINDING Structures."

Length Values

The length value itself is a ULONG data type. The value stored in this ULONG depends on the data type as follows: