Class , how to encapsulate this :
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Class , how to encapsulate this :

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    2

    Class , how to encapsulate this :

    ok this my 1st time writing classes so i need help on
    how to write a class for this :

    Code:
    void CADOMFC1View::OnMenuitem32771()
    {
       _RecordsetPtr pRecordSet;
       CADOMFC1Doc * pDoc;
       pDoc = GetDocument();
       _bstr_t bstrQuery("SELECT * FROM App_Student");
       _variant_t vRecsAffected(0L);
       try
       {
         pRecordSet = pDoc->m_pConnection->Execute(bstrQuery,&vRecsAffected,adOptionUnspecified);
         
         if (!pRecordSet->GetadoEOF())
        {
          CListCtrlEx& ctlList = (CListCtrlEx&) GetListCtrl();
          ctlList.DeleteAllItems();
          while(ctlList.DeleteColumn(0));
          ctlList.AddColumn(" ID ",0);
          ctlList.AddColumn(" Name ",1);
          ctlList.AddColumn(" Gender ",2);
          ctlList.AddColumn(" Subject 1 ",3);
          ctlList.AddColumn(" Subject 2 ",4);
          ctlList.AddColumn(" Class ",5);
          int i = 0;
          _variant_t ID;
          _variant_t vName;
          _variant_t cGender;
          _variant_t vSubject1;
          _variant_t vSubject2;
          _variant_t Class;
          while (!pRecordSet->GetadoEOF())
          {
            ID = pRecordSet->GetCollect(L"ID");
            ctlList.AddItem(i,0,(_bstr_t) ID);
            vName = pRecordSet->GetCollect(L"vName");
            ctlList.AddItem(i,1,(_bstr_t) vName);
            cGender = pRecordSet->GetCollect(L"cGender");
            ctlList.AddItem(i,2,(_bstr_t) cGender);
            vSubject1 = pRecordSet->GetCollect(L"vSubject1");
            ctlList.AddItem(i,3,(_bstr_t) vSubject1);
            vSubject2 = pRecordSet->GetCollect(L"vSubject2");
            ctlList.AddItem(i,4,(_bstr_t) vSubject2);
            Class = pRecordSet->GetCollect(L"Class");
            ctlList.AddItem(i,5,(_bstr_t) Class);
    
            pRecordSet->MoveNext();
            i++;
          }
        }
        pRecordSet->Close();
      }
      catch( _com_error &e )
      {
        // Get info from _com_error
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());
        TRACE( "Exception thrown for classes generated by #import" );
        TRACE( "\tCode = %08lx\n", e.Error());
        TRACE( "\tCode meaning = %s\n", e.ErrorMessage());
        TRACE( "\tSource = %s\n", (LPCTSTR) bstrSource);
        TRACE( "\tDescription = %s\n", (LPCTSTR) bstrDescription);
      }
      catch(...)
      {
        TRACE( "*** Unhandled Exception ***" );
      }
    
    }


    THANKS
    Last edited by ovidiucucu; April 7th, 2009 at 04:35 AM. Reason: added CODE tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center