什么错误啊?你应该把异常信息贴出来。
另外,Rec1是一个查询语句,返回了结果集你没有处理的前提下,就再次打开Rec2,这样基于同一个连接连续打开两个Recordset是不行的,必须一次处理一个结果集才行。在MessageBox(“2“)后面,加上Rec1.Close()试试看把。

解决方案 »

  1.   

    try
    {
    Conn.CreateInstance( __uuidof( Connection ) );
    Conn->Open(pBuffer,"","",-1);
    sprintf(pBuffer,"Select * From Jobs");
    Rec1.CreateInstance( __uuidof( Recordset ) );
    Rec1->CursorLocation = adUseClient;
    Rec1->Open(_variant_t(pBuffer),Conn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
    sprintf(pBuffer,"Select * Form titles");
    Rec1->Close();
    Rec2.CreateInstance( __uuidof( Recordset ) );
    Rec2->CursorLocation = adUseClient;
    Rec2->Open(_variant_t(pBuffer),Conn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
    Rec2->Close();
    Conn->Close();
    }
    catch(_com_error *e)
    {
    MessageBox(e->ErrorMessage());
    return;
    }
    catch(...)
    {
    MessageBox("Error Happened");
    if(Rec1->State == adStateOpen)
    Rec1->Close();
    if(Rec2->State == adStateOpen)
    Rec2->Close();
    if(Conn->State == adStateOpen)
    Conn->Close();
    return;
    }still Have Error.
    Catch Error in Catch(...)
      

  2.   

    我也有出错过,好象是连着用两个recordset不容易定位记录,我后来的用法是,打开一个recordset前打开连接,读完记录后关闭连接,再打开,再用第二个recordset,然后再关闭连接
    一般在用recordset时要打开记录集,用完后要关闭
      

  3.   

    to microyzy(毛毛叉) 
    错在什么地方?解决马上结分
      

  4.   

    一个Connection连接可以供N个Recordset对象使用的,就像你去商店买东西,不必每买一件东西都要退出商店重新进去一样。