#include <afxdb.h>
...
void CDBTestDlg::OnBnClickedBtnSave()
{
// TODO: Add your control notification handler code here
CDatabase db;
...
db.OpenEx("DSN=messenger;");
db.ExecuteSQL("...");
}
class CNamecard : public CRecordset
{
..
// Field/Param Data
//{{AFX_FIELD(CNamecard, CRecordset)
CString m_strName;
CString m_strPhone;
..
BOOL m_bSex;
CTime m_dateBirth;
//}}AFX_FIELD
..
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CNamecard)
public:
virtual CString GetDefaultConnect(); // Default connection string
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
//}}AFX_VIRTUAL
..
};
CNamecard::CNamecard(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CNamecard)
m_strName = _T("");
m_strPhone = _T("");
..
m_bSex = FALSE;
m_nFields = n;
//}}AFX_FIELD_INIT
m_nDefaultType = snapshot;
}
CString CNamecard::GetDefaultConnect()
{
return _T("ODBC;DSN=Namecard");
}
CString CNamecard::GetDefaultSQL()
{
return _T("[Namecard]");
}
void CNamecard::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CNamecard)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Text(pFX, _T("[strName]"), m_strName);
RFX_Text(pFX, _T("[strPhone]"), m_strPhone);
..
RFX_Bool(pFX, _T("[bSex]"), m_bSex);
RFX_Date(pFX, _T("[dateBirth]"), m_dateBirth);
//}}AFX_FIELD_MAP
}
CNamecard namecard;
if(!namecard.Open()) // 레코드셋 열기
{
AfxMessageBox(_T("데이터 소스와 연결하지 못했습니다."));
}
..
while(!namecard.IsEOF())
{
.. namecard.m_strPhone .. namecard.m_bSex .. namecard.m_dateBirth ..
namecard.MoveNext();
}