这是MSDN中返回多个纪录集的代码
_bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;"
            "Initial Catalog=pubs;User Id=sa;Password=;");    try
    {
        // Open recordset from Authors table.
        TESTHR(pRstCompound.CreateInstance(__uuidof(Recordset)));        // Pass the Cursor type and Lock type to the Recordset.
        pRstCompound->Open("SELECT * FROM authors; SELECT * FROM stores;" 
            "SELECT * FROM jobs", strCnn, adOpenForwardOnly, 
            adLockReadOnly, adCmdText);        // Display results from each SELECT statement.
        int intCount = 1;
        while(!(pRstCompound==NULL))
        {
            printf("\n\nContents of recordset #%d\n", intCount);            while(!pRstCompound->EndOfFile)
            {
                index.iVal = 0;
                printf("%s\t", (LPCSTR)(_bstr_t)pRstCompound->\
                            GetFields()->GetItem(& index)->Value);
                index.iVal = 1;
                printf("%s\n", (LPCSTR)(_bstr_t)pRstCompound->\
                                Fields->GetItem(& index)->Value);
                pRstCompound->MoveNext();
                int intLine = intLine + 1;
                if (intLine % 22 == 0)
                {
                    printf("\nPress any key to continue...");
                    getch();
                    //Clear the screen for the next display.
                    system("cls"); 
                }
            }
            long    lngRec = 0;
            pRstCompound = pRstCompound->NextRecordset((VARIANT *)lngRec);
            printf("\nPress any key to continue...");
            getch();
            intCount = intCount + 1;
        }
    }    catch(_com_error &e)
    {
       // Notify the user of errors if any.
       // Pass a connection pointer accessed from the Recordset.
        _variant_t vtConnect = pRstCompound->GetActiveConnection();        // GetActiveConnection returns connect string if connection
        // is not open, else returns Connection object.
        switch(vtConnect.vt)
        {
            case VT_BSTR:
                PrintComError(e);
                break;
            case VT_DISPATCH:
                PrintProviderError(vtConnect);
                break;
            default:
                printf("Errors occured.");
                break;
        }
    }
这里边没有关闭的代码,有那位高手指点一下这有没有问题

解决方案 »

  1.   

    应该说它只是例程的一部分。
      

  2.   

    我不是高手,所以没有看出问题
      

  3.   

    这已经是例程的核心了,其他部分没有关于纪录集的代码了。我是问这里边没有显式的关闭纪录集的代码会不会有问题?(不是说纪录集使用后要关闭吗)
      

  4.   

    请问怎么提问题,怎么发问~!我为什么不能发问,只能跟贴啊~!我有分的呀~!紧急~!
      

  5.   

    我知道怎么关闭纪录集。我只是问上面这段代码会不会有问题(他没有显式关闭)
      

  6.   

    你进入一个小的分类就会出现提问选项,你就可以发问了