bool get_resultsettmp(_RecordsetPtr &ors,const char *SqlStatement)
{
if(!ors)
return false;
try
{
if(ors->State == adStateOpen)
{
ors->Close();
}
//ors->CursorLocation = adUseClient; ors->Open(SqlStatement,
m_Connection.GetInterfacePtr(),
adOpenForwardOnly,
adLockOptimistic,
adCmdText);
return true;
}
catch(_com_error &e)
{
ErrorReport("异常语句:%s", SqlStatement);
dump_com_error(e,"get_resultsettmp");
}
catch(...)
{ }
return false;
}
CString sql;
//char sql[1024];
_RecordsetPtr rs;
int MaxID=0;
sql.Format("select max(PlayListID) as ID FROM PlayList where DevCode='%s'", (LPCTSTR)DevCode);
rs.CreateInstance(__uuidof(Recordset));
if (get_resultsettmp(rs,(LPCTSTR)sql)==false)
{
freerecordsetptr(rs);
return 0;
}
else
{
ErrorReport("RecordCount:%d",(int)rs->GetRecordCount());
if ((int)rs->GetRecordCount()==0)   //此处返回值一直是-1
{
ErrorReport("RecordCount:%d",rs->GetRecordCount());
return 0;
}
else
{
CString strFieldName="";
strFieldName="ID";
FieldsPtr fp=rs->Fields;
if (fp->Item[_variant_t(strFieldName)]->Value.vt!=VT_NULL)
{
return fp->Item[_variant_t(strFieldName)]->Value;
}
}
}
用rs->eof||rs->bof怎么也提示错误啊

解决方案 »

  1.   

    这个不太知道。

    rs.CreateInstance(__uuidof(Recordset));
    前增加一句试试呢?
    CoInitialize(NULL);
      

  2.   


    while操作记录集可以这样
    while(!ors->adoEOF) //不为空则提取数据
    if单条语句的操作可以
    if(ors->RecordCount > 0) //不为空
      

  3.   

    应该是这里的问题adOpenForwardOnly
      

  4.   

    加异常捕获看是什么错误
    try
    {
    //你的ADO代码
    }
    catch (_com_error& e)
    {
    CString strMsg;
    strMsg.Format(_T("错误描述:%s\n错误消息%s"), 
    (LPCTSTR)e.Description(),
    (LPCTSTR)e.ErrorMessage());
    AfxMessageBox(strMsg);
    }
      

  5.   


    捕获异常为NULL,RecordCount为-1,adoEOF和adoBOF都为0
    if(!m_pLastTime->adoEOF)
    {
            MessageBox((const char*)(_bstr_t)m_pLastTime->RecordCount);
    MessageBox((const char*)(_bstr_t)m_pLastTime->adoEOF);
    MessageBox((const char*)(_bstr_t)m_pLastTime->adoBOF);
    try{
    bLst.Format(_T((const char*)(_bstr_t)m_pLastTime->GetCollect("maxt")));}
    catch (_com_error& e) { CString strMsg; strMsg.Format(_T("错误描述:%s\n错误消息%s"),          (LPCTSTR)e.Description(),         (LPCTSTR)e.ErrorMessage()); AfxMessageBox(strMsg); }目测跟查询SQL有关,我的是这样的,和楼上的同一个问题,SQL里都是取max()
    select max(v_time) as maxt from v_record where v_cust_num='123456'
    怎么解决呢?
      

  6.   

    补充一下,select max(v_time) as maxt from v_record where v_cust_num='123456'返回值应该为空的。应该是在空结果集中取max的问题