CString max;
int hr;
str.Format("USE Temp select count(*) as tatol from Index_Temp");
try  //用try{}catch{}块处理数据库ADO操作异常
{
m_pRecordset.CreateInstance("ADODB.Recordset");  
hr = m_pRecordset->Open(_variant_t(str),_variant_t((IDispatch *)m_pConn,true),adOpenKeyset,adLockReadOnly,adCmdText);
_variant_t var = m_pRecordset->GetCollect("tatol");
if(var.vt != VT_NULL) 

max= (LPCSTR)_bstr_t(var);

}
catch(_com_error &e) 

AfxMessageBox(e.Description()); 

解决方案 »

  1.   

    首先hr的值是0,也就是Open成功,但是就是GetCollect取字段值的时候就取不出来
      

  2.   

      catch(_com_error &e) 
        { 
            AfxMessageBox(e.Description()); 
        } 提示:对象关闭时,不允许操作
      

  3.   

    问题已经解决,请不要在回答,不会给分啦,问题出在str.Format("USE Temp select count(*) as tatol from Index_Temp");
    把use Temp去掉就可以了
      

  4.   

    是不是你的字段名错了,这个tatol是什么意思?total?
      

  5.   

    USE Temp是不是选择数据库,可以用Excute执行USE Temp,再OpenUSE Temp select count(*) as tatol from Index_Temp
    //--》
    select count(*) as tatol from Index_Temp
      

  6.   

    实际上是我上面还有段代码是连接数据库的,我直接连接进去了Temp数据库如过在USE Temp的话就会出问题,一直以为USE这个语句就算上面连接了在加上去也没关系,现在事实证明我是错的