我现在数据表中有一项Spend存放的数据库类型是货币。ACCESS数据库。
我想用SUM(Spend)把里面的钱数统计出来。然后通过MessageBox显示出来。 m_pCommand->CommandText = "SELECT SUM(Spend) FROM data";
try
{
m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdText);
vTotal = m_pRecordset->GetCollect(_variant_t((long)0));
}
catch(_com_error e)
{
CATCH_ERROR;
return ;
}
CString str;
//关键就是下面这一句,但我不知道返回的SUM到底存到哪去了,
//因为这个_variant_t型的vTotal后面跟一堆放数的,我不知道存在哪个里了。
//请帮忙看看啊。
//str.Format(_T("%2f"),vTotal.lVal);
AfxMessageBox(str);
我想用SUM(Spend)把里面的钱数统计出来。然后通过MessageBox显示出来。 m_pCommand->CommandText = "SELECT SUM(Spend) FROM data";
try
{
m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdText);
vTotal = m_pRecordset->GetCollect(_variant_t((long)0));
}
catch(_com_error e)
{
CATCH_ERROR;
return ;
}
CString str;
//关键就是下面这一句,但我不知道返回的SUM到底存到哪去了,
//因为这个_variant_t型的vTotal后面跟一堆放数的,我不知道存在哪个里了。
//请帮忙看看啊。
//str.Format(_T("%2f"),vTotal.lVal);
AfxMessageBox(str);
试试
AfxMessageBox(CString(_bstr_t(vTotal)));
或者在vTotal = m_pRecordset->GetCollect(_variant_t((long)0));
之后添加vTotal.ChangeType(VARTYPE vartype);调用,参数为你要改的目标类型
而我改成:
str.Format(_T("%2f"),vTotal.lVal/10000.0);后是能显示了,但显示出来的后面的小数点有点多了,
我只想要两位.另外问问 eeixy2000(eeixy2000)怎么跟踪看Vtotal的类型啊?