RT

解决方案 »

  1.   

    BOOL CDlgRecordset::GetMicCol()
    {
    //OnSelchangeComTable();

    /*try 
    {  
    m_pRecordset=theApp.m_pConnection->OpenSchema(adSchemaColumns);

    while(!(m_pRecordset->adoEOF))   
    {         
    //»ñÈ¡±í¸ñ    
        _bstr_t col_name = m_pRecordset->Fields->GetItem("TABLE_NAME")->Value;
    //_bstr_t col_name = m_pRecordset->Fields->GetItem(str)->Value;
    //»ñÈ¡±í¸ñÀàÐÍ        
    _bstr_t col_type = m_pRecordset->Fields->GetItem("COLUMN_TYPE")->Value;
    //¹ýÂËһϣ¬Ö»Êä³ö±í¸ñÃû³Æ£¬ÆäËûµÄÊ¡ÂÔ
    if ( strcmp(((LPCSTR)col_type),"COLUMN")==0)
    {
    m_cmbCol.AddString((LPCSTR)col_name);
    }       
    m_pRecordset->MoveNext();    
    }   
    m_pRecordset->Close();  
    }*/
    _bstr_t   mStrSQL;
    CString   strSQL;
    CString   strColName;
    BSTR      bstrColName;
    long      ColCount,i; 
    Field *   field = NULL;
    HRESULT   hr;
    Fields *  fields = NULL;
    LPCTSTR   nameField;
    CString str;

    int nTable=m_cmbTable.GetCurSel();
    m_cmbTable.GetLBText(nTable,str);
    // strSQL.Format("SELECT * FROM %s",str);
    strSQL="select * from " + str;
    mStrSQL=strSQL;/* if(m_pRecordset->State==1)
    {
    m_pRecordset->Close();
    }
    m_pRecordset->Open(mStrSQL,
    theApp.m_pConnection.GetInterfacePtr(),
    adOpenKeyset,
    adLockOptimistic,
    adCmdText);*/
    hr=m_pRecordset->get_Fields(&fields);//µÃµ½¼Ç¼¼¯µÄ×ֶμ¯ºÏ

    if(SUCCEEDED(hr))
    fields->get_Count(&ColCount);//µÃµ½¼Ç¼¼¯µÄ×ֶμ¯ºÏÖеÄ×ֶεÄ×ܸöÊý
    for(i=0;i<ColCount;i++)
    {
    fields->Item[i]->get_Name(&bstrColName);//&micro;&Atilde;&micro;&frac12;&frac14;&Ccedil;&Acirc;&frac14;&frac14;&macr;&Ouml;&ETH;&micro;&Auml;×&Ouml;&para;&Icirc;&Atilde;&ucirc;
    // UINT uType=fields->Item[i]->Type;
    strColName=bstrColName;
    nameField=strColName;
    m_cmbCol.AddString(nameField); }
    // OnSelchangeComTable();
    if(SUCCEEDED(hr))
    fields->Release();//&Ecirc;&Iacute;·&Aring;&Ouml;&cedil;&Otilde;&euml;
    // &sup1;&Oslash;±&Otilde;&frac14;&Ccedil;&Acirc;&frac14;&frac14;&macr;
    /// m_pRecordset->Close();
    /*catch(_com_error e)///&sup2;&para;×&frac12;&Ograve;ì&sup3;&pound; 
    {  
    ::MessageBox(NULL,e.Description(),"&Igrave;á&Ecirc;&frac34;",MB_OK);
    return FALSE;
    }*/

    return true;}
      

  2.   

    编译有错误,Fields *fields=NULL
    不能实例化抽象类
      

  3.   

    是不是这样啊
    FieldsPtr   fds;
    FieldPtr   fd;
    fds = m_pRecordset->GetFields();   
    for(int   i = 0;i < fds->GetCount();i ++)  
    {  
    fd = fds->GetItem(_variant_t(short(i)));  
    CString str = fd->GetName();
    }