|
博客刚开始写,还不太完善,希望各位看官可以多提意见,所有代码都是测试通过可以跑起来的,如果遇到什么问题可以留言。
首先看一下程序运行的效果:
个人信息管理界面:
右键菜单有增加、修改,点击就到了个人信息界面:
图一
接下来看一下是怎么实现的:
(1)信息管理界面用到了一个表格控件list Control,还用到了右键菜单
***********PersonalInformationTabDlg.h***********
#pragma once
#include "afxwin.h"
#include "afxcmn.h"
class ConnectDB;
// 个人信息管理对话框
class PersonalInformationTabDlg : public CDialogEx
{
DECLARE_DYNAMIC(PersonalInformationTabDlg)
public:
PersonalInformationTabDlg(CWnd* pParent = NULL); // 标准构造函数
virtual ~PersonalInformationTabDlg();
// 对话框数据
enum { IDD = IDD_PERSONALINFOTABDLG };
protected:
HICON m_hIcon;
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
//初始化tab
afx_msg LRESULT OnInitdialog(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
private:
//tab对象
CListCtrl m_tabPersonalInfo;
int m_nMaxID;
public:
//弹出右键菜单
afx_msg void OnNMRClickList3(NMHDR *pNMHDR, LRESULT *pResult);
//添加
afx_msg void OnMenuClickedAdd();
//修改
afx_msg void OnMenuClickChange();
//删除
afx_msg void OnMenuClickDelete();
private:
bool _seleteDB();
};
***********PersonalInformationTabDlg.cpp***********
#include "stdafx.h"
#include "PersonalInformation.h"
#include "PersonalInformationTabDlg.h"
#include "afxdialogex.h"
#include "PersonalInformationDlg.h"
#include "ConnectDB.h"
// PersonalInformationTabDlg 对话框
IMPLEMENT_DYNAMIC(PersonalInformationTabDlg, CDialogEx)
PersonalInformationTabDlg::PersonalInformationTabDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(PersonalInformationTabDlg::IDD, pParent)
{
m_nMaxID = 0;
}
PersonalInformationTabDlg::~PersonalInformationTabDlg()
{
}
void PersonalInformationTabDlg::DoDataExchange(CDataExchange* pDX)
{
//添加变量
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST3, m_tabPersonalInfo);
}
//添加事件处理程序
BEGIN_MESSAGE_MAP(PersonalInformationTabDlg, CDialogEx)
ON_MESSAGE(WM_INITDIALOG, &PersonalInformationTabDlg::OnInitdialog)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_32771, &PersonalInformationTabDlg::OnMenuClickedAdd)
ON_NOTIFY(NM_RCLICK, IDC_LIST3, &PersonalInformationTabDlg::OnNMRClickList3)
ON_COMMAND(ID_32772, &PersonalInformationTabDlg::OnMenuClickChange)
ON_COMMAND(ID_32773, &PersonalInformationTabDlg::OnMenuClickDelete)
END_MESSAGE_MAP()
// PersonalInformationTabDlg 消息处理程序
afx_msg LRESULT PersonalInformationTabDlg::OnInitdialog(WPARAM wParam, LPARAM lParam)
{
CDialogEx::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
CRect rect;
// 获取编程语言列表视图控件的位置和大小
m_tabPersonalInfo.GetClientRect(&rect);
// 为列表视图控件添加全行选中和栅格风格
m_tabPersonalInfo.SetExtendedStyle(m_tabPersonalInfo.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
// 为列表视图控件添加四列
m_tabPersonalInfo.InsertColumn(0, _T("编号"), LVCFMT_CENTER, rect.Width()/5, 0);
m_tabPersonalInfo.InsertColumn(1, _T("姓名"), LVCFMT_CENTER, rect.Width()/5, 1);
m_tabPersonalInfo.InsertColumn(2, _T("年龄"), LVCFMT_CENTER, rect.Width()/5, 2);
m_tabPersonalInfo.InsertColumn(3, _T("性别"), LVCFMT_CENTER, rect.Width()/5, 3);
m_tabPersonalInfo.InsertColumn(4, _T("爱好"), LVCFMT_CENTER, rect.Width()/5, 4);
m_tabPersonalInfo.SetColumnWidth(0,40);
m_tabPersonalInfo.SetColumnWidth(1,80);
m_tabPersonalInfo.SetColumnWidth(2,80);
m_tabPersonalInfo.SetColumnWidth(3,80);
m_tabPersonalInfo.SetColumnWidth(4,200);
_seleteDB();
return 0;
}
bool PersonalInformationTabDlg::_seleteDB()
{
bool bSuccessed = false;
CDatabase * pDatabase = NULL; // 数据库
CRecordset * pRecSet = NULL; // 记录集
bSuccessed = ConnectDB::getInstance()->connectDB(pDatabase, pRecSet);
if (!bSuccessed)
{
return false;
MessageBox(_T("建立数据库连接失败!"), _T("提示框"), MB_OK | MB_ICONHAND);
}
int nAge = 0;
int nID = 0;
CString strName, strSex, strAge, strHobby, strID;
CDBVariant var; // 字段类型
BOOL b = pRecSet->Open(AFX_DAO_USE_DEFAULT_TYPE, _T("SELECT * FROM PERSONALINFO"), NULL);
int nIndex = 0 ;
while(!pRecSet->IsEOF()) // 有没有到表结尾
{
pRecSet->GetFieldValue(L"ID", var);
nID = var.m_iVal;
strID.Format(L"%d", nID);
m_tabPersonalInfo.InsertItem(nIndex, strID);
pRecSet->GetFieldValue(L"姓名", var);
strName = *(var.m_pstring);
m_tabPersonalInfo.SetItemText(nIndex, 1, strName);
pRecSet->GetFieldValue(L"年龄", var);
nAge = var.m_iVal;
strAge.Format(L"%d", nAge);
m_tabPersonalInfo.SetItemText(nIndex, 2, strAge);
pRecSet->GetFieldValue(L"性别", var);
strSex = *(var.m_pstring);
m_tabPersonalInfo.SetItemText(nIndex, 3, strSex);
pRecSet->GetFieldValue(L"爱好", var);
strHobby = *(var.m_pstring);
m_tabPersonalInfo.SetItemText(nIndex, 4, strHobby);
pRecSet->MoveNext();
++nIndex ;
}
m_nMaxID = nID;
pRecSet->Close();
return bSuccessed;
}
void PersonalInformationTabDlg::OnMenuClickedAdd()
{
// 增加
INT_PTR nRes; // 用于保存DoModal函数的返回值
PersonalInforData stuData;
stuData.m_stuFlag = -1;
stuData.m_stuID = m_nMaxID + 1;
CPersonalInformationDlg dlg( stuData); // 定义对话框类CAdditionDlg的对象dlg
nRes = dlg.DoModal(); // 弹出对话框dlg
if (nRes == IDOK) // 判断返回值是否为OK按钮(其ID为IDOK)
{
//确定
// TODO: 在此放置处理何时用
// “确定”来关闭对话框的代码
}
else if (nRes == IDCANCEL) // 判断返回值是否为Cancel按钮(其ID为IDCANCEL)
{
//取消
// TODO: 在此放置处理何时用
// “取消”来关闭对话框的代码
return;
}
CString strAge;
CString strCurID;
stuData = dlg.getStructData();
strCurID.Format (L"%d",m_nMaxID + 1);
m_tabPersonalInfo.InsertItem(m_nMaxID, strCurID);
m_tabPersonalInfo.SetItemText(m_nMaxID, 1, stuData.m_stuName);
m_tabPersonalInfo.SetItemText(m_nMaxID, 3, stuData.m_stuSex);
strAge.Format(L"%d", stuData.m_stuAge);
m_tabPersonalInfo.SetItemText(m_nMaxID, 2, strAge);
m_tabPersonalInfo.SetItemText(m_nMaxID, 4, stuData.m_stuHobby);
m_nMaxID ++;
}
void PersonalInformationTabDlg::OnNMRClickList3(NMHDR *pNMHDR, LRESULT *pResult)
{
// 右键菜单
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
*pResult = 0;
POINT point;
GetCursorPos(&point);
ScreenToClient(&point);
if (point.x == -1 && point.y == -1) //判断是否在窗口外面
{
CRect rect;
m_tabPersonalInfo.GetClientRect(rect); //得到窗口客户区的大小
m_tabPersonalInfo.ClientToScreen(rect); //转化为屏幕坐标
point = rect.TopLeft();//获取左上角坐标
//point.Offset(5, 5); //坐标偏移5,5
}
CMenu menu;//声明菜单对象
menu.LoadMenu(IDR_MENU1);//从应用程序的可执行文件中加载菜单资源
CMenu* pPopup ;
pPopup= menu.GetSubMenu(0); //获得第一个弹出菜单的指针,也就是菜单中的第一个弹出菜单
// 将坐标值由客户坐标转换为屏幕坐标
ClientToScreen(&point);
ASSERT(pPopup != NULL); //p断言不为空
CWnd* pWndPopupOwner = this;//当前类的指针
//下面就是弹出菜单
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner);
}
void PersonalInformationTabDlg::OnMenuClickChange()
{
// 修改
PersonalInforData stuData ;
int istat=m_tabPersonalInfo.GetSelectionMark();
stuData.m_stuFlag = 0;
stuData.m_stuID = StrToInt(m_tabPersonalInfo.GetItemText(istat,0));
stuData.m_stuName = m_tabPersonalInfo.GetItemText(istat,1);
stuData.m_stuAge = StrToInt(m_tabPersonalInfo.GetItemText(istat,2));
stuData.m_stuSex = m_tabPersonalInfo.GetItemText(istat,3);
stuData.m_stuHobby = m_tabPersonalInfo.GetItemText(istat,4);
INT_PTR nRes;
CPersonalInformationDlg dlg( stuData); // 定义对话框类CAdditionDlg的对象dlg
nRes = dlg.DoModal(); // 弹出对话框dlg
CString strCurID;
CString strAge;
stuData = dlg.getStructData();
strCurID.Format (L"%d",stuData.m_stuID);
m_tabPersonalInfo.SetItemText(stuData.m_stuID - 1, 1, stuData.m_stuName);
m_tabPersonalInfo.SetItemText(stuData.m_stuID - 1, 3, stuData.m_stuSex);
strAge.Format(L"%d", stuData.m_stuAge);
m_tabPersonalInfo.SetItemText(stuData.m_stuID - 1, 2, strAge);
m_tabPersonalInfo.SetItemText(stuData.m_stuID - 1, 4, stuData.m_stuHobby);
}
void PersonalInformationTabDlg::OnMenuClickDelete()
{
// 删除
int nSel=m_listCoord.GetSelectionMark();
m_listCoord.DeleteItem(nSel);
}
(2)信息界面用到了Static Text ,Edit Control ,Radio Button等
***********PersonalInformationDlg.h***********
#pragma once
#include "afxwin.h"
class ConnectDB;
struct PersonalInforData
{
int m_stuFlag; //-1为增加,0为修改
CString m_stuName ;
int m_stuAge ;
CString m_stuSex ;
CString m_stuHobby;
int m_stuID;
};
// 个人信息 对话框
class CPersonalInformationDlg : public CDialogEx
{
// 构造
public:
CPersonalInformationDlg( PersonalInforData stuData, CWnd* pParent = NULL); // 标准构造函数
~CPersonalInformationDlg();
// 对话框数据
enum { IDD = IDD_PERSONALINFODLG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
HICON m_hIcon;
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnEnChangeEdit1();
afx_msg void OnBnClickedOk();
private:
CEdit m_edtName; //姓名
CEdit m_edtAge; //年龄s
CEdit m_edtHobby; //个人爱好
CButton m_btnWoman; //女
CButton m_btnMan; //男
PersonalInforData m_stuData;
private:
bool _saveDataToDB(CString strName, int nAge, CString strHobby, bool bIsWoman);//保存数据到数据库
void saveStructData();
public:
PersonalInforData getStructData();
};
***********PersonalInformationDlg.cpp***********
#include "stdafx.h"
#include "PersonalInformation.h"
#include "PersonalInformationDlg.h"
#include "afxdialogex.h"
#include "ConnectDB.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void add();
afx_msg void OnMenuClickedAdd();
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CMFC_PersonalInformationDlg 对话框
CPersonalInformationDlg::CPersonalInformationDlg(PersonalInforData stuData, CWnd * pParent /*=NULL*/)
: CDialogEx(CPersonalInformationDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_stuData = stuData;
}
CPersonalInformationDlg::~CPersonalInformationDlg()
{
}
void CPersonalInformationDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, m_edtName);
DDX_Control(pDX, IDC_EDIT2, m_edtAge);
DDX_Control(pDX, IDC_EDIT3, m_edtHobby);
DDX_Control(pDX, IDC_RADIO1, m_btnWoman);
DDX_Control(pDX, IDC_RADIO2, m_btnMan);
}
BEGIN_MESSAGE_MAP(CPersonalInformationDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK, &CPersonalInformationDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// CMFC_PersonalInformationDlg 消息处理程序
BOOL CPersonalInformationDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
if (-1 != m_stuData.m_stuFlag)
{
m_edtName.ReplaceSel(m_stuData.m_stuName);
m_edtHobby.ReplaceSel(m_stuData.m_stuHobby);
CString strAge ;
strAge.Format(_T("%d"),m_stuData.m_stuAge); ;
m_edtAge.ReplaceSel(strAge);
if (m_stuData.m_stuSex == "女")
{
CheckDlgButton(IDC_RADIO1, 1);
}
else
{
CheckDlgButton(IDC_RADIO2, 1);
}
//m_btnWoman.ReplaceSel(stuData.m_stuName);
}
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void CPersonalInformationDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CPersonalInformationDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CPersonalInformationDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CPersonalInformationDlg::OnBnClickedOk()
{
INT_PTR nRes;
CString strName;
GetDlgItemText(IDC_EDIT1,strName);
if (strName == "" )
{
// 显示消息对话框
nRes = MessageBox(_T("名字不能为空,请您将信息填写完整"), _T("提示框"), MB_OK | MB_ICONHAND );
return;
}
CString strHobby;
GetDlgItemText(IDC_EDIT3,strHobby);
if (strHobby == "")
{
// 显示消息对话框
nRes = MessageBox(_T("爱好不能为空,请您将信息填写完整"), _T("提示框"), MB_OK | MB_ICONHAND );
return;
}
bool bIsWoman = false;
if (!(m_btnMan.GetCheck() || m_btnWoman.GetCheck()))
{
// 显示消息对话框
nRes = MessageBox(_T("性别不能为空,请您将信息填写完整"), _T("提示框"), MB_OK | MB_ICONHAND );
return;
}
if (m_btnWoman.GetCheck())
{
bIsWoman = true;
}
CString strAge;
GetDlgItemText(IDC_EDIT2,strAge);
if (strAge == "")
{
// 显示消息对话框
nRes = MessageBox(_T("年龄不能为空,请您将信息填写完整"), _T("提示框"), MB_OK | MB_ICONHAND );
return;
}
int nAge = StrToInt(strAge);
if (nAge < 0 || nAge > 120 )
{
// 显示消息对话框
nRes = MessageBox(_T("年龄输入不合法,请您重新输入"), _T("提示框"), MB_OK | MB_ICONHAND );
return;
}
saveStructData();
_saveDataToDB(strName, nAge, strHobby, bIsWoman);
// TODO: 在此添加控件通知处理程序代码
CDialogEx::OnOK();
}
bool CPersonalInformationDlg::_saveDataToDB(CString strName, int nAge, CString strHobby, bool bIsWoman)
{
bool bSuccessed = false;
CDatabase * pDatabase = NULL; // 数据库
CRecordset * pRecSet = NULL; // 记录集
bSuccessed = ConnectDB::getInstance()->connectDB(pDatabase, pRecSet);
if (!bSuccessed)
{
return false;
MessageBox(_T("建立数据库连接失败!"), _T("提示框"), MB_OK | MB_ICONHAND);
}
CString strSex = bIsWoman ? L"女" : L"男";
CString strSql = L"";
if (-1 ==m_stuData.m_stuFlag)
{
//增加
strSql.Format(L"INSERT INTO PERSONALINFO(姓名, 性别, 年龄, 爱好,ID) VALUES('%s', '%s', %d, '%s',%d)", strName, strSex, nAge, strHobby,m_stuData.m_stuID);
pDatabase->ExecuteSQL(strSql);
}
else
{
//修改
strSql.Format(L"UPDATE PERSONALINFO SET 姓名 = '%s', 性别 = '%s', 年龄 = %d, 爱好 = '%s' WHERE ID = %d", strName, strSex, nAge, strHobby, m_stuData.m_stuID);
pDatabase->ExecuteSQL(strSql);
}
return true;
}
void CPersonalInformationDlg::saveStructData()
{
CString strName;
CString strAge;
CString strHobby;
GetDlgItemText(IDC_EDIT1,strName);
GetDlgItemText(IDC_EDIT2,strAge);
GetDlgItemText(IDC_EDIT3,strHobby);
m_stuData.m_stuName = strName;
m_stuData.m_stuAge = StrToInt(strAge);
m_stuData.m_stuHobby = strHobby;
m_stuData.m_stuSex = m_btnWoman.GetCheck() ? L"女" : L"男";
}
PersonalInforData CPersonalInformationDlg::getStructData()
{
return m_stuData;
}
(3)数据库连接,我用了一个单例
***********ConnectDB.h***********
#pragma once
class ConnectDB
{
public:
static ConnectDB * getInstance();
static void release();
bool connectDB(CDatabase *& pDatabase, CRecordset *& pRecSet);
private:
ConnectDB();
~ConnectDB();
private:
static ConnectDB * m_pInstance;
CDatabase * m_pDatabase; // 数据库
CRecordset * m_pRecSet; // 记录集
};
***********ConnectDB.cpp***********
#include "stdafx.h"
#include "ConnectDB.h"
ConnectDB * ConnectDB::m_pInstance = NULL;
ConnectDB::ConnectDB()
{
m_pDatabase = NULL;
m_pRecSet = NULL;
}
ConnectDB::~ConnectDB(void)
{
//关闭记录集及库
m_pRecSet->Close();
m_pDatabase->Close();
if (m_pRecSet != NULL)
{
delete m_pRecSet;
m_pRecSet = NULL;
}
if (m_pDatabase != NULL)
{
delete m_pDatabase;
m_pDatabase = NULL;
}
}
ConnectDB * ConnectDB::getInstance()
{
if (m_pInstance == NULL)
{
m_pInstance = new ConnectDB;
}
return m_pInstance;
}
void ConnectDB::release()
{
if (m_pInstance != NULL)
{
delete m_pInstance;
m_pInstance = NULL;
}
}
bool ConnectDB::connectDB(CDatabase *& pDatabase, CRecordset *& pRecSet)
{
BOOL bSuccessed = FALSE;
if (m_pDatabase == NULL)
{
m_pDatabase = new CDatabase();
bSuccessed = m_pDatabase->Open(L"ODBC;DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)};DSN='';DBQ=..\\Debug\\DemoDatabase.mdb");
if (!bSuccessed)
{
return false;
}
}
if (m_pRecSet == NULL)
{
m_pRecSet = new CRecordset(m_pDatabase);
bSuccessed = m_pRecSet->Open(AFX_DAO_USE_DEFAULT_TYPE, _T("SELECT * FROM PERSONALINFO"), NULL);
m_pRecSet->Close();
if (!bSuccessed)
{
return false;
}
}
pDatabase = m_pDatabase;
pRecSet = m_pRecSet;
return true;
} |
|