Sets the string to a particular type.

void SetString( 
   LPCTSTR lpszSrc, 
   VARTYPE vtSrc  


  • lpszSrc
    A null-terminated string to be copied into the new COleVariant object.

  • VtSrc
    The VARTYPE for the new COleVariant object.


The parameter vtSrc must be VT_BSTR (UNICODE) or VT_BSTRT (ANSI). SetString is typically used to set strings to ANSI, since the default for the COleVariant::COleVariant constructor with a string or string pointer parameter and no VARTYPE is UNICODE.

A DAO recordset in a non-UNICODE build expects strings to be ANSI. Thus, for DAO functions that use COleVariant objects, if you are not creating a UNICODE recordset, you must use the COleVariant::COleVariant( lpszSrc, vtSrc ) form of constructor with vtSrc set to VT_BSTRT (ANSI) or use SetString with vtSrc set to VT_BSTRT to make ANSI strings. For example, the CDaoRecordset functions CDaoRecordset::Seek and CDaoRecordset::SetFieldValue use COleVariant objects as parameters. These objects must be ANSI if the DAO recordset is not UNICODE.


Header: afxdisp.h

See Also


COleVariant Class

Hierarchy Chart