想用ADO动态邦定的方法,我使用的是DataGrid,IADODatabinding到底怎么用呢?不懂!

解决方案 »

  1.   

    BOOL CDlgRecordset::QueryRecord()
    {
    _CommandPtr cmd;  
    _RecordsetPtr rs;  
    _ConnectionPtr conn; 
    _variant_t vra;
    VARIANT *vt1 = NULL;
    try
    {
    /* cmd.CreateInstance( __uuidof(Command));
    rs.CreateInstance(__uuidof(Recordset));
    conn.CreateInstance(__uuidof(Connection));*/ UpdateData(TRUE);
    theApp.m_pConnection->PutCursorLocation(adUseClient);

    /* conn->CursorLocation = adUseClient;

    conn->Open(_bstr_t( theApp.m_pConnection.GetInterfacePtr() ), L"", L"", -1);
    cmd->ActiveConnection = conn;

       cmd->CommandText = (_bstr_t) m_strQuery;
    cmd->CommandType = adCmdText;
    rs = cmd->Execute(&vra,vt1, adCmdText);*/
    /*rs->PutRefActiveConnection(theApp.m_pConnection);
    rs->Open((_bstr_t)m_strQuery,
    theApp.m_pConnection.GetInterfacePtr(),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);*/
    ///     ((CTestDllApp*)(&theApp))->m_pConnection
    /// m_pRecordset.CreateInstance(__uuidof(Recordset));

    /* m_pRecordset->Open((_bstr_t)m_strQuery,
    _variant_t((IDispatch*)theApp.m_pConnection, TRUE),
    adOpenStatic,
    adLockOptimistic,
    adCmdText);*/
       if(m_pRecordset->State==1)
    {
    m_pRecordset->Close();
    }
    m_pRecordset->Open((_bstr_t)m_strQuery,
    theApp.m_pConnection.GetInterfacePtr(),//»ñÈ¡¿â½Ó¿âµÄIDispatchÖ¸Õë
    adOpenStatic,
    adLockOptimistic,
    adCmdText);
    /* m_DataGrid.SetRefDataSource(NULL);
    m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
    m_DataGrid.Refresh();*/
    }
    catch (_com_error &e)
    {
    ::MessageBox(NULL,e.Description(),"Ìáʾ",MB_OK);
    }

    m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
    m_DataGrid.Refresh();
    UpdateData(FALSE);
    //m_pRecordset->Close();
    return true;
     
    }
      

  2.   

    CDataGrid::SetRefDataSource()
    CDataGrid::Rebind()
      

  3.   

    CDataGrid::SetRefDataSource()  //设定数据源
    CDataGrid::Rebind() //绑定