The information in this article applies to:
SYMPTOMS
The MFC DAO Classes contain methods that accept COleVariant arguments. For
example, CDaoRecordset::Seek(), CDaoRecordset::SetFieldValue(), and
CDaoRecordset::SetBookMark() accept COleVariant arguments. You may find
that these functions do not perform correctly if you are building a
non-UNICODE build of your application and you are assigning a string to a
COleVariant and passing the variant to one of these methods.
This code causes only the first letters of each string to be copied to the
database with a non-UNICODE build. In this case, the letter M will be
copied to both fields.
CAUSEMFC creates ANSI DAO objects when building non-UNICODE builds and creates UNICODE DAO objects when building UNICODE builds. For example, look at the following code in AfxDaoInit():
The ANSI DAO objects require ANSI BSTRs for any strings that they receive.
When you initialize a COleVariant object using:
-or-
The COleVariant will contain a UNICODE BSTR regardless of whether the build
is UNICODE or non-UNICODE. This is not what DAO expects.
RESOLUTIONThere are two techniques you can use to initialize the COleVariant properly. If you are only concerned about setting the BSTR value of the COleVariant at construction time, use this code:
The VT_BSTRT constant specifies that the BSTR will be a UNICODE BSTR with a
UNICODE build and it will be a ANSI BSTR in a non-UNICODE build.If you need to change the value of the variant often, you may want to create a helper function:
With Visual C++ 4.2 or higher, COleVariant contains a SetString() function
that can be used instead of the FillVariant() function above.
STATUSThis behavior is by design. Additional query words: Seek SetFieldValue SetCacheStart SetBookMark SetParamValue
Keywords : kbprg kbDAO kbDatabase kbMFC kbVC |
Last Reviewed: August 5, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |