• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            kenlistian

            厚積薄發(fā). 勤為槳,思為帆

               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理 ::
              73 隨筆 :: 4 文章 :: 22 評論 :: 0 Trackbacks
            使用_commandPtr 處理存儲過程時,當在存儲過程中需要返回結(jié)果集合和返回參數(shù)時,一般在任何語言調(diào)用的ado中
            存儲過程控件都無法同時返回,這里http://www.pkvs.com/data/mssql/19323.html給了我們答案。

            使用CreateParameter(),而是調(diào)用CommandPtr的Refresh()函數(shù)先從數(shù)據(jù)庫中查詢參數(shù).
            _ConnectionPtr m_pConn;
            m_pConn.CreateInstance(__uuidof(Connection));
            m_pConn->Open("driver={SQL Server};server=127.0.0.1;DATABASE=pub;UID=sa;PWD=", "","",0);

            _CommandPtr  m_pCommand;
            m_pCommand.CreateInstance(__uuidof(Command));
            _RecordsetPtr m_pRecordset;
            m_pRecordset.CreateInstance(__uuidof(Recordset));

            m_pCommand->ActiveConnection = m_pConn;
            m_pCommand->CommandText = "SP_XX";              //存儲過程名
            m_pCommand->PutCommandType(adCmdStoredProc);
            m_pCommand->Parameters->Refresh();              //從數(shù)據(jù)庫查詢參數(shù)信息
            //我不建議使用refresh,這個內(nèi)部的處理速度還不如用createparamter好,

            long cnt = m_pCommand->Parameters->GetCount();//取得參數(shù)的個數(shù)
            for(long k=1;k<cnt;k++)
            { //由于ADO中認為返回值是第一個參數(shù),因此這里用k=1濾掉第一個參數(shù)
                   m_pCommand->Parameters->GetItem(k)->Value = XXX;//按存儲過程的參數(shù)順序給參數(shù)賦值
            }

            以執(zhí)行這個存儲過程了,返回m_pRecordset將返回集合,
                m_pRecordset = m_pCommand->Execute(0,0,adCmdStoredProc);
            這個時候,如果接下來用
               _variant_t ret_val = m_pCommand->Parameters->GetItem((long)0)->Value;
            那么將得不到值
            而如果像下面這樣調(diào)用的話就可以得到返回值了
            m_pRecordset->Close();
            _variant_t output_para = m_pCommand->Parameters->GetItem((long)0)->Value;
            MS ADO.net給這一現(xiàn)象的回復是:
             You can think of a stored procedure as a function in your code. The function doesn’t return a value until it has executed all of its code. If the stored procedure returns results and you haven’t finished processing these results, the stored procedure hasn’t really finished executing. Until you’ve closed the DataReader, the return and output parameters of your Command won’t contain the values returned by your stored procedure.
            也就是說Execute()函數(shù)應該看成是直到m_pRecordset關(guān)掉以后才會正確返回.


            posted on 2007-09-18 10:17 kenlistian 閱讀(603) 評論(0)  編輯 收藏 引用
            中文字幕久久欲求不满| 亚洲精品久久久www| 亚洲AV乱码久久精品蜜桃| 欧洲成人午夜精品无码区久久| 四虎国产精品免费久久| 人人狠狠综合88综合久久| 久久天天躁狠狠躁夜夜96流白浆 | 国产精品久久99| 亚洲天堂久久精品| 婷婷国产天堂久久综合五月| 99久久国产热无码精品免费| 精品无码久久久久久国产| 欧美精品国产综合久久| 久久久久久久99精品免费观看| 久久久综合香蕉尹人综合网| 久久丫精品国产亚洲av不卡| 国产成人综合久久精品尤物| 伊人久久综合精品无码AV专区 | av色综合久久天堂av色综合在 | 久久久久亚洲精品日久生情| 久久99国产精品一区二区| 精品久久久无码中文字幕天天| 99久久99久久精品国产片果冻| www.久久热.com| 亚洲国产日韩综合久久精品| 夜夜亚洲天天久久| 国产综合久久久久| 久久久久高潮综合影院| 性高朝久久久久久久久久| 狠狠色丁香婷婷综合久久来来去 | 国内精品久久久久影院免费| 亚洲欧洲久久久精品| 欧美亚洲国产精品久久蜜芽| 国产精品禁18久久久夂久| 久久精品国产免费观看三人同眠| 国产精品内射久久久久欢欢| 77777亚洲午夜久久多喷| 日韩精品久久无码人妻中文字幕 | 久久精品中文字幕无码绿巨人 | 久久九九久精品国产| 国内精品久久久久久久久|