CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: DBase file(s)

  1. #1
    Join Date
    Jun 1999
    Location
    Virginia
    Posts
    54

    DBase file(s)

    In my dialog app, I need/want to work (open, read, write, browse, etc.) with DBase files (including indexes). Is there any suggestion/solution using MFC? (DAO, etc)
    Thanks for your replies.



  2. #2
    Guest

    Re: DBase file(s)

    I use DAO. Here is a short example of how using a mythical employee database

    From Employee.h

    /////////////////////////////////////////////////////////////////////////////
    // CEmployee DAO recordset

    class CEmployee : public CDaoRecordset
    {
    public:
    CString m_LastName;
    CString m_FirstName;
    short m_IdNo;
    CEmployee(CDaoDatabase* pDatabase = NULL);
    DECLARE_DYNAMIC(CEmployee)

    // Field/Param Data
    //{{AFX_FIELD(CEmployee, CDaoRecordset)
    //}}AFX_FIELD

    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CEmployee)
    public:
    virtual CString GetDefaultDBName(); // Default database name
    virtual CString GetDefaultSQL(); // Default SQL for Recordset
    virtual void DoFieldExchange(CDaoFieldExchange* pFX); // RFX support
    //}}AFX_VIRTUAL

    // Implementation
    #ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
    #endif
    };

    //{{AFX_INSERT_LOCATION}}
    // Microsoft Developer Studio will insert additional declarations immediately before the previous line.

    from Employee.cpp
    /////////////////////////////////////////////////////////////////////////////
    // CEmployee

    IMPLEMENT_DYNAMIC(CEmployee, CDaoRecordset)

    CEmployee::CEmployee(CDaoDatabase* pdb)
    : CDaoRecordset(pdb)
    {
    //{{AFX_FIELD_INIT(CEmployee)
    m_IdNo = 0;
    m_FirstName = "";
    m_LastName = "";
    m_nFields = 3;
    //}}AFX_FIELD_INIT
    m_nDefaultType = dbOpenTable;
    }


    CString CEmployee::GetDefaultDBName()
    {
    return _T("T:\\TMC\\ACCTS\\");
    }

    CString CEmployee::GetDefaultSQL()
    {
    return _T("Employee");
    }

    void CEmployee:oFieldExchange(CDaoFieldExchange* pFX)
    {
    //{{AFX_FIELD_MAP(CEmployee)
    pFX->SetFieldType(CDaoFieldExchange:utputColumn);
    DFX_Short(pFX,_T("[ID_NO]"), m_IdNo);
    DFX_Text(pFX,_T("[FIRSTNAME]"),m_FirstName);
    DFX_Text(pFX,_T("[LASTNAME]"),m_LastName);
    //}}AFX_FIELD_MAP
    }

    /////////////////////////////////////////////////////////////////////////////
    // CEmployee diagnostics

    #ifdef _DEBUG
    void CEmployee::AssertValid() const
    {
    CDaoRecordset::AssertValid();
    }

    void CEmployee:ump(CDumpContext& dc) const
    {
    CDaoRecordset:ump(dc);
    }
    #endif //_DEBUG

    From my main.cpp

    m_EmplJet.Open("T:\\TMC\\ACCTS\\",FALSE,FALSE,_T("dBase IV"));
    m_EmplSet = new CEmployee(&m_EmplJet);
    m_EmplSet->Open();
    m_EmplSet->SetCurrentIndex("ID_NO");

    // Grab their name

    double id = atof(some_id);
    COleVariant search_v(id);
    if (m_EmplSet->Seek("=",&search_v))
    {
    m_FullName = m_EmplSet->m_FirstName;
    m_FullName += " ";
    m_FullName += m_EmplSet->m_LastName;
    }
    else
    {
    m_FullName = "";
    }








  3. #3
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    Re: DBase file(s)

    I follow everything except where is m_EmplJet initialized and with what? Any help would be appreciated as I think this is what I am looking for to finish my project! The line I am looking at is:
    m_EmplJet.Open("T:\\TMC\\ACCTS\\",FALSE,FALSE,_T("dBase IV"));

    Thanks!
    Charlie

    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured