CDBVariant Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CDBVariant Class.

Represents a variant data type for the MFC ODBC classes.

class CDBVariant  

Public Constructors

NameDescription
CDBVariant::CDBVariantConstructs a CDBVariant object.

Public Methods

NameDescription
CDBVariant::ClearClears the CDBVariant object.

Public Data Members

NameDescription
CDBVariant::m_dwTypeContains the data type of the currently stored value. Type DWORD.

Public Union Members

NameDescription
CDBVariant::m_boolValContains a value of type BOOL.
CDBVariant::m_chValContains a value of type unsigned char.
CDBVariant::m_dblValContains a value of type double.
CDBVariant::m_fltValContains a value of type float.
CDBVariant::m_iValContains a value of type short.
CDBVariant::m_lValContains a value of type long.
CDBVariant::m_pbinaryContains a pointer to an object of type CLongBinary.
CDBVariant::m_pdateContains a pointer to an object of type TIMESTAMP_STRUCT.
CDBVariant::m_pstringContains a pointer to an object of type CString.
CDBVariant::m_pstringAStores a pointer to an ASCII CString object.
CDBVariant::m_pstringWStores a pointer to a wide CString object.

CDBVariant does not have a base class.

CDBVariant is similar to COleVariant; however, CDBVariant does not use OLE. CDBVariant allows you to store a value without worrying about the value's data type. CDBVariant tracks the data type of the current value, which is stored in a union.

Class CRecordset utilizes CDBVariant objects in three member functions: GetFieldValue, GetBookmark, and SetBookmark. For example, GetFieldValue allows you to dynamically fetch data in a column. Because the data type of the column may not be known at run time, GetFieldValue uses a CDBVariant object to store the column's data.

CDBVariant

Header: afxdb.h

Creates a NULL CDBVariant object.

CDBVariant();

Remarks

Sets the m_dwType data member to DBVT_NULL.

Call this member function to clear the CDBVariant object.

void Clear();

Remarks

If the value of the m_dwType data member is DBVT_DATE, DBVT_STRING, or DBVT_BINARY, Clear frees the memory associated with the union pointer member. Clear sets m_dwType to DBVT_NULL.

The CDBVariant destructor calls Clear.

Stores a value of type BOOL.

Remarks

The m_boolVal data member belongs to a union. Before accessing m_boolVal, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_BOOL, then m_boolVal will contain a valid value; otherwise, accessing m_boolVal will produce unreliable results.

Stores a value of type unsigned char.

Remarks

The m_chVal data member belongs to a union. Before accessing m_chVal, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_UCHAR, then m_chVal contains a valid value; otherwise, accessing m_chVal will produce unreliable results.

Stores a value of type double.

Remarks

The m_dblVal data member belongs to a union. Before accessing m_dblVal, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_DOUBLE, then m_dblVal contains a valid value; otherwise, accessing m_dblVal will produce unreliable results.

This data member contains the data type for the value that is currently stored in the CDBVariant object's union data member.

Remarks

Before accessing this union, you must check the value of m_dwType in order to determine which union data member to access. The following table lists the possible values for m_dwType and the corresponding union data member.

m_dwTypeUnion data member
DBVT_NULLNo union member is valid for access.
DBVT_BOOLm_boolVal
DBVT_UCHARm_chVal
DBVT_SHORTm_iVal
DBVT_LONGm_lVal
DBVT_SINGLEm_fltVal
DBVT_DOUBLEm_dblVal
DBVT_DATEm_pdate
DBVT_STRINGm_pstring
DBVT_BINARYm_pbinary
DBVT_ASTRINGm_pstringA
DBVT_WSTRINGm_pstringW

Stores a value of type float.

Remarks

The m_fltVal data member belongs to a union. Before accessing m_fltVal, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_SINGLE, then m_fltVal contains a valid value; otherwise, accessing m_fltVal will produce unreliable results.

Stores a value of type short.

Remarks

The m_iVal data member belongs to a union. Before accessing m_iVal, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_SHORT, then m_iVal contains a valid value; otherwise, accessing m_iVal will produce unreliable results.

Stores a value of type long.

Remarks

The m_lVal data member belongs to a union. Before accessing m_lVal, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_LONG, then m_lVal contains a valid value; otherwise, accessing m_lVal will produce unreliable results.

Stores a pointer to an object of type CLongBinary.

Remarks

The m_pbinary data member belongs to a union. Before accessing m_pbinary, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_BINARY, then m_pbinary contains a valid pointer; otherwise, accessing m_pbinary will produce unreliable results.

Stores a pointer to an object of type TIMESTAMP_STRUCT.

Remarks

The m_pdate data member belongs to a union. Before accessing m_pdate, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_DATE, then m_pdate contains a valid pointer; otherwise, accessing m_pdate will produce unreliable results.

For more information about the TIMESTAMP_STRUCT data type, see the topic C Data Types in Appendix D of the ODBC Programmer's Reference in the Windows SDK.

Stores a pointer to an object of type CString.

Remarks

The m_pstring data member belongs to a union. Before accessing m_pstring, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_STRING, then m_pstring contains a valid pointer; otherwise, accessing m_pstring will produce unreliable results.

Stores a pointer to an ASCII CString object.

Remarks

The m_pstringA data member belongs to a union. Before accessing m_pstringA, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_ASTRING, then m_pstringA contains a valid pointer; otherwise, accessing m_pstringA will produce unreliable results.

Stores a pointer to a wide CString object.

Remarks

The m_pstringW data member belongs to a union. Before accessing m_pstringW, first check the value of CDBVariant::m_dwType. If m_dwType is set to DBVT_WSTRING, then m_pstringW contains a valid pointer; otherwise, accessing m_pstringW will produce unreliable results.

Hierarchy Chart
CRecordset Class

Show: