description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CDBVariant Class |
CDBVariant Class |
11/04/2016 |
|
|
de23609c-c560-4b24-bd6b-9d8903fd5b49 |
Represents a variant data type for the MFC ODBC classes.
class CDBVariant
Name | Description |
---|---|
CDBVariant::CDBVariant | Constructs a CDBVariant object. |
Name | Description |
---|---|
CDBVariant::Clear | Clears the CDBVariant object. |
Name | Description |
---|---|
CDBVariant::m_dwType | Contains the data type of the currently stored value. Type DWORD . |
Name | Description |
---|---|
CDBVariant::m_boolVal | Contains a value of type BOOL. |
CDBVariant::m_chVal | Contains a value of type unsigned char . |
CDBVariant::m_dblVal | Contains a value of type double . |
CDBVariant::m_fltVal | Contains a value of type float . |
CDBVariant::m_iVal | Contains a value of type short . |
CDBVariant::m_lVal | Contains a value of type long . |
CDBVariant::m_pbinary | Contains a pointer to an object of type CLongBinary . |
CDBVariant::m_pdate | Contains a pointer to an object of type TIMESTAMP_STRUCT. |
CDBVariant::m_pstring | Contains a pointer to an object of type CString . |
CDBVariant::m_pstringA | Stores a pointer to an ASCII CString object. |
CDBVariant::m_pstringW | Stores 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();
Sets the m_dwType data member to DBVT_NULL.
Call this member function to clear the CDBVariant
object.
void Clear();
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.
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
.
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
.
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.
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_dwType | Union data member |
---|---|
DBVT_NULL | No union member is valid for access. |
DBVT_BOOL | m_boolVal |
DBVT_UCHAR | m_chVal |
DBVT_SHORT | m_iVal |
DBVT_LONG | m_lVal |
DBVT_SINGLE | m_fltVal |
DBVT_DOUBLE | m_dblVal |
DBVT_DATE | m_pdate |
DBVT_STRING | m_pstring |
DBVT_BINARY | m_pbinary |
DBVT_ASTRING | m_pstringA |
DBVT_WSTRING | m_pstringW |
Stores a value of type float
.
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
.
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
.
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.
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.
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.
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.
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.
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.