-
May 12th, 2005, 11:54 AM
#1
using VARIANT or converting to CString
I'v been searching the whole Internet for the following problem :
how to convert a CString to a Variant
my problem :
I'm working on an ADO database and I want to use the filter of the _recordsetPtr
like this :
_RecordsetPtr m_pRS ;
CString strFilter = "Name LIKE 'a*'" ;
m_pRS.Filter = strFilter ;
only problem : the Filter only takes a variant
or maybe can someone explain to me how I must use the VARIANT type?
I already searched MSDN and the web, but nowhere any good explanation on VARIANT
TIA
-
May 12th, 2005, 01:08 PM
#2
Re: using VARIANT or converting to CString
Originally Posted by da_cobra
how to convert a CString to a Variant
CString to VARIANT Conversion: Method I
Code:
// Your CString
CString strInput (_T ("Test String"));
VARIANT varString;
// Create a BSTR, assign it.
varString.bstrVal = strInput.AllocSysString ();
// Set Variant Type
varString.vt = VT_BSTR;
// Use the VARIANT
// De-Allocate it: Don't forget this step if you are using Raw Variants
::VariantClear (&varString);
CString to VARIANT Conversion: Method II
Code:
// Using the CComVariant: Smart Wrapper Class for VARIANT
CComVariant varSmartVariantString (strInput);
// Use varSmartVariantString...
Originally Posted by da_cobra
or maybe can someone explain to me how I must use the VARIANT type?
Q. What is a VARIANT?
A. A VARIANT is a structure.
Code:
typedef struct tagVARIANT VARIANT;
typedef struct tagVARIANT VARIANTARG;
struct tagVARIANT
{
// ... variant members...
};
It can support many data-types because it (the structure) contains a UNION as a member.
The Variant Type is identified by the member VARIANT::vt
Originally Posted by da_cobra
I already searched MSDN and the web, but nowhere any good explanation on VARIANT
The link above contains detailed information.
Let me know if your query is solved.
-
May 12th, 2005, 10:40 PM
#3
Re: using VARIANT or converting to CString
thx alot! this really helped me!!!
-
May 13th, 2005, 04:00 AM
#4
Re: using VARIANT or converting to CString
You are welcome.
Ciao,
Sid!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|