string CAdoConnection::VariantToString(const _variant_t &var)
{
string strValue;
TCHAR szValue[1024] = {0x00};
switch (var.vt)
{
case VT_BSTR://字符串
case VT_LPSTR://字符串
case VT_LPWSTR://字符串
strValue = (LPCTSTR)(_bstr_t)var;
break;
case VT_I1:
case VT_UI1:
_stprintf(szValue, _T("%d"), var.bVal);
strValue = szValue;
break;
case VT_I2://短整型
_stprintf(szValue, _T("%d"), var.iVal);
strValue = szValue;
break;
case VT_UI2://无符号短整型
_stprintf(szValue, _T("%d"), var.uiVal);
strValue = szValue;
break;
case VT_INT://整型
_stprintf(szValue, _T("%d"), var.intVal);
strValue = szValue;
break;
case VT_I4: //整型
_stprintf(szValue, _T("%d"), var.lVal);
strValue = szValue;
break;
case VT_I8: //长整型
_stprintf(szValue, _T("%ld"), var.bVal);
strValue = szValue;
break;
case VT_UINT://无符号整型
_stprintf(szValue, _T("%u"), var.uintVal);
strValue = szValue;
break;
case VT_UI4: //无符号整型
_stprintf(szValue, _T("%u"), var.ulVal);
strValue = szValue;
break;
case VT_UI8: //无符号长整型
_stprintf(szValue, _T("%u"), var.ulVal);
strValue = szValue;
break;
case VT_VOID:
_stprintf(szValue, _T("%8x"), (unsigned int)var.byref);
strValue = szValue;
break;
case VT_R4://浮点型
_stprintf(szValue, _T("%.4f"), var.fltVal);
strValue = szValue;
break;
case VT_R8://双精度型
_stprintf(szValue, _T("%.8f"), var.dblVal);
strValue = szValue;
break;
case VT_DECIMAL: //小数
_stprintf(szValue, _T("%.8f"), (double)var);
strValue = szValue;
break;
case VT_CY:
{
COleCurrency cy = var.cyVal;
strValue = cy.Format();
}
break;
case VT_BLOB:
case VT_BLOB_OBJECT:
case 0x2011:
strValue = "[BLOB]";
break;
case VT_BOOL://布尔型
strValue = var.boolVal ? "TRUE" : "FALSE";
break;
case VT_DATE: //日期型
{
DATE dt = var.date;
COleDateTime da = COleDateTime(dt);
strValue = da.Format("%Y-%m-%d %H:%M:%S");
}
break;
case VT_NULL://NULL值
strValue = "VT_NULL";
break;
case VT_EMPTY://空
strValue = "";
break;
case VT_UNKNOWN://未知类型
default:
strValue = "UN_KNOWN";
break;
}
return strValue;
}
VARIANT 类型说明
最新推荐文章于 2025-07-12 15:11:18 发布