DBGrid 只能显示一行数据,请高手指教,是怎么回事?没有用数据绑定,
代码是这样的:for(i=0;i<n;i++)
{
    m_CdtGrid.SetRow(i); //就是这里有问题,第二次执行就会出现"应用程序内部错误"这样的错误
    m_CdtGrid.SetCol(0);
    sprintf("mess","%d",i);
    m_CdtGrid.SetText(mess);
    
    m_CdtGrid.SetCol(1)
    m_CdtGrid.SetText(mess);
}

解决方案 »

  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(),//&raquo;&ntilde;&Egrave;&iexcl;&iquest;&acirc;&frac12;&Oacute;&iquest;&acirc;&micro;&Auml;IDispatch&Ouml;&cedil;&Otilde;&euml;
    adOpenStatic,
    adLockOptimistic,
    adCmdText);
    /* m_DataGrid.SetRefDataSource(NULL);
    m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
    m_DataGrid.Refresh();*/
    }
    catch (_com_error &e)
    {
    ::MessageBox(NULL,e.Description(),"&Igrave;á&Ecirc;&frac34;",MB_OK);
    }

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