这个问题的答案比较广泛:
我所知道常用的
1。在执行的SQL语句一般都是_bstr_t
2.Connection 中的RecordsAffected 为VARIANT
3.使用get_Value()获得的记录的值为 VAARIANT
等等。。。
_bstr_t 中记录了字符串的长度,
_variant_t 记录有数据的类型和数据的值
如 _variant_t ttt;
ttt.vt=I4_VT; 表示数据类型为整数
ttt.lVal 为数据的值
转载:
/*
将 _variant_t 类型的变量,转换成字符串(比如如果是数字,则转换成数字对应的字符串 :如 10.2 -> "10.200000")
*/
_variant_t var;
CString str; //转换以后的字符串
//以下代码演示如何转换为C标准字符串型
if (var.vt == VT_I4)
{
long lNum;
char szCh[21];
str=var.bstrVal;
WideCharToMultiByte
(CP_ACP, 0, var.bstrVal, -1,
szCh, sizeof(szCh), NULL, NULL);
}
//以下代码演示如何转换成逻辑型
if( var.vt == VT_BOOL)
{
BOOL bVar;
lNum=var.lVal;
bVar= var.boolVar==0? FALSE : TRUE;
}
//以下代码演示为其余类型(补充)
switch(var.vt)
{
case VT_BSTR: //var is BSTR type
str=var.bstrVal;
break;
case VT_I2: //var is short int type
str.Format("%d",(int)var.iVal);
break;
case VT_I4: //var is long int type
str.Format("%d",var.lVal);
break;
case VT_R4: //var is float type
str.Format("%10.6f",(double)var.fltVal);
break;
case VT_R8: //var is double type
str.Format("%10.6f",var.dblVal);
break;
case VT_CY: //var is CY type
str=COleCurrency(var).Format();
break;
case VT_DATE: //var is DATE type
str=COleDateTime(var).Format();
break;
case VT_BOOL: //var is VARIANT_BOOL
str= (var.boolVal==0) ?"FALSE": "TRUE";
break;
default:
str.Format("Unk type %d/n",var.vt);
TRACE("Unknown type %d/n",var.vt);
}
http://blog.donews.com/martinleilei/archive/2007/10/09/1217580.aspx
struct tagVARIANT
{
union
{
struct __tagVARIANT
{
VARTYPE vt;
WORD wReserved1;
WORD wReserved2;
WORD wReserved3;
union {
LONGLONG llval; // VT_I8.
LONG lVal; // VT_I4.
BYTE bVal; // VT_UI1.
SHORT iVal; // VT_I2.
FLOAT fltVal; // VT_R4.
DOUBLE dblVal; // VT_R8.
VARIANT_BOOL boolVal; // VT_BOOL.
_VARIANT_BOOL bool;
SCODE scode; // VT_ERROR.
CY cyVal; // VT_CY.
DATE date; // VT_DATE.
BSTR bstrVal; // VT_BSTR.
IUnknown * punkVal; // VT_UNKNOWN.
IDispatch * pdispVal; // VT_DISPATCH.
SAFEARRAY * parray; // VT_ARRAY|*.
BYTE * pbVal; // VT_BYREF|VT_UI1.
SHORT * piVal; // VT_BYREF|VT_I2.
LONG * plVal; // VT_BYREF|VT_I4.
LONGLONG * pllVal; // VT_BYREF|VT_I8.
FLOAT * pfltVal; // VT_BYREF|VT_R4.
DOUBLE * pdblVal; // VT_BYREF|VT_R8.
VARIANT_BOOL * pboolVal; // VT_BYREF|VT_BOOL.
_VARIANT_BOOL * pbool;
SCODE * pscode; // VT_BYREF|VT_ERROR.
CY * pcyVal; // VT_BYREF|VT_CY.
DATE * pdate; // VT_BYREF|VT_DATE.
BSTR * pbstrVal; // VT_BYREF|VT_BSTR.
IUnknown ** ppunkVal; // VT_BYREF|VT_UNKNOWN.
IDispatch ** ppdispVal; // VT_BYREF|VT_DISPATCH.
SAFEARRAY ** pparray; // VT_BYREF|VT_ARRAY.
VARIANT * pvarVal; // VT_BYREF|VT_VARIANT.
PVOID * byref; // Generic ByRef.
CHAR cVal; // VT_I1.
USHORT uiVal; // VT_UI2.
ULONG ulVal; // VT_UI4.
ULONGLONG ullVal; // VT_UI8.
INT intVal; // VT_INT.
UINT uintVal; // VT_UINT.
DECIMAL * pdecVal // VT_BYREF|VT_DECIMAL.
CHAR * pcVal; // VT_BYREF|VT_I1.
USHORT * puiVal; // VT_BYREF|VT_UI2.
ULONG * pulVal; // VT_BYREF|VT_UI4.
ULONGLONG * pullVal; // VT_BYREF|VT_UI8.
INT * pintVal; // VT_BYREF|VT_INT.
UINT * puintVal; // VT_BYREF|VT_UINT.
struct __tagBRECORD
{
PVOID pvRecord;
IRecordInfo *pRecInfo;
} __VARIANT_NAME_4;
} __VARIANT_NAME_3;
} __VARIANT_NAME_2;
DECIMAL decVal;
} __VARIANT_NAME_1;
};
};
http://msdn.microsoft.com/en-us/library/ms221627%28v=VS.85%29.aspx