C++ ADO Oracle 绑定变量

vc 6.0,ado,oracle。
        _RecordsetPtr pRst;       
        _CommandPtr   pComm;
        pRst.CreateInstance("ADODB.Recordset";

        while (m_lsbQuery.GetCount())
        {
                m_lsbQuery.DeleteString(0);
        }
        CString strSql;
        strSql.Format("select * from test_bv where id=? or id=?";
        try
        {
                for (int i = 0;i < 100;i++)
                {
                        pComm.CreateInstance("ADODB.Command";
                        pComm->ActiveConnection = m_pConn;
                        pComm->CommandType = adCmdText;
                        pComm->CommandText = (_bstr_t)strSql;
                        VARIANT vt;
                        vt.vt = VT_I2;
                        vt.intVal = i + 1;
                        pComm->Parameters->Append(pComm->CreateParameter("v1",adInteger,adParamInput,sizeof(int),vt));
                        vt.intVal = i + 2;
                        pComm->Parameters->Append(pComm->CreateParameter("v2",adInteger,adParamInput,sizeof(int),vt));
                        pRst = pComm->Execute(NULL,NULL,adCmdText);
                }

                while (!pRst->adoEOF)
                {
                        CString strName = pRst->GetCollect("name".bstrVal;
                        CString strID;
                        strID.Format("%.10d",pRst->GetCollect("id".lVal);
                        _variant_t v = pRst->Fields->GetItem("birth"->Value;
                        COleDateTime o(v);
                        CString strTime;
                        strTime.Format("%d-%.2d-%.2d %.2d:%.2d:%.2d",o.GetYear(),o.GetMonth(),o.GetDay(),o.GetHour(),o.GetMinute(),o.GetSecond());
                        CString strTemp;
                        strTemp += strID;
                        strTemp += strName;
                        strTemp += strTime;
                        m_lsbQuery.AddString(strTemp);
                        pRst->MoveNext();
                }
        }
        catch (_com_error e)
        {

        }

你可能感兴趣的:(oracle,VC)