Click to See Complete Forum and Search --> : DBase file(s)


Stan
June 8th, 1999, 08:18 AM
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.

June 8th, 1999, 09:53 AM
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::DoFieldExchange(CDaoFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CEmployee)
pFX->SetFieldType(CDaoFieldExchange::outputColumn);
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::Dump(CDumpContext& dc) const
{
CDaoRecordset::Dump(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 = "";
}

Charlie Curtis
July 13th, 1999, 07:58 AM
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