• <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

            厚積薄發. 勤為槳,思為帆

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

            使用CreateParameter(),而是調用CommandPtr的Refresh()函數先從數據庫中查詢參數.
            _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();              //從數據庫查詢參數信息
            //我不建議使用refresh,這個內部的處理速度還不如用createparamter好,

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

            以執行這個存儲過程了,返回m_pRecordset將返回集合,
                m_pRecordset = m_pCommand->Execute(0,0,adCmdStoredProc);
            這個時候,如果接下來用
               _variant_t ret_val = m_pCommand->Parameters->GetItem((long)0)->Value;
            那么將得不到值
            而如果像下面這樣調用的話就可以得到返回值了
            m_pRecordset->Close();
            _variant_t output_para = m_pCommand->Parameters->GetItem((long)0)->Value;
            MS ADO.net給這一現象的回復是:
             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()函數應該看成是直到m_pRecordset關掉以后才會正確返回.


            posted on 2007-09-18 10:17 kenlistian 閱讀(619) 評論(0)  編輯 收藏 引用
            久久国产精品视频| 国产亚洲精品久久久久秋霞 | 久久午夜无码鲁丝片| 精品久久久无码中文字幕天天| 久久精品国产福利国产秒| 伊人久久综合热线大杳蕉下载| 国产亚洲美女精品久久久| 日日狠狠久久偷偷色综合0| 久久亚洲精品无码VA大香大香| 国产精品视频久久久| 99久久精品国产综合一区| 伊人精品久久久久7777| 精品久久777| 久久综合亚洲欧美成人| 久久国产高清一区二区三区| 欧美丰满熟妇BBB久久久| 亚洲AⅤ优女AV综合久久久| 97久久香蕉国产线看观看| 波多野结衣久久一区二区| 久久精品国产清自在天天线| 国产精品久久久亚洲| 国产成人综合久久精品红| 久久免费视频6| 国产AⅤ精品一区二区三区久久 | 国产精品免费久久久久影院 | 亚洲va中文字幕无码久久不卡| 色噜噜狠狠先锋影音久久| 无码伊人66久久大杳蕉网站谷歌| 久久免费视频一区| 美女写真久久影院| 久久精品国产一区| 国产精品99久久99久久久| 久久综合噜噜激激的五月天| 欧美亚洲另类久久综合婷婷| 久久黄视频| 久久亚洲天堂| 久久久精品人妻一区二区三区蜜桃| 少妇熟女久久综合网色欲| 国产精品久久久久免费a∨| 一级做a爰片久久毛片免费陪| 色综合久久88色综合天天 |