用micorsoft route dbgrid

解决方案 »

  1.   

    你是说用micorsoft remotedata control吗?我用了,我可以显示数据表,但是我的目的是显示我的结果记录集
      

  2.   

    void CDgDlg::OnOK() 
    {
    // set datasource of DBGrid dynamically
    //notes : call AfxOleInit in CXXApp::InitInstance()
    // I also add a line in stdafx.h 
    //#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
       try
       {
          _ConnectionPtr pConn("ADODB.Connection");
          _RecordsetPtr  pRst("ADODB.Recordset");
          pConn->Open("Provider=sqloledb;Data Source=Dell1;"
             "Initial Catalog=testdb;User Id=sa;Password=;",
             "", "", adConnectUnspecified);
          pRst->Open(
             "table1",
             _variant_t((IDispatch *) pConn, true),
             adOpenStatic,
             adLockReadOnly,
             adCmdTable);
      //CDataGrid m_grid; is a member of CDgDlg.
    m_grid.SetRefDataSource(pRst.Detach());
       }
       catch (_com_error &e)
       {
      char mybuf[10240];
          wsprintf(mybuf,"Description = '%s'\n", (char*) e.Description());
      AfxMessageBox(mybuf);
       }
    }