Welcome

首页 / 软件开发 / C++ / 树型控件实现数据库的访问

树型控件实现数据库的访问2008-04-20方锡武本人意图将数据库中的内容加入树型控件中,通过建立数据库,再与树型控件相连,实现数据库的访问。查询结构清晰明了,操作方便。

现将其方法阐述如下:

1、建数据库:建立Access数据库,数据库结构和内容见程序包access文件。

2、建立单文档不基于数据库支持的应用程序工程,视图类继承于CFormView,本程序

工程名Ppp,视图类名为CPppView。

3、建立数据库集,数据源采用DAO连接,继承于CDaoRecordset,类名为 CShengSet

4、在Stdafx.h文件中加入支持DAO连接的数据源头文件

#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdao.h> //加入行,实现本视图类对Access数据库的访问
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif

5、在PppView.h中加入数据集头文件中。

#include"ShengSet.h"

同时定义数据集类变量

public:
CShengSet *m_ShengSet;

6、在PppDoc.h中加入数据集头文件中。

#include"ShengSet.h"

同时定义数据集类变量

public:
CShengSet m_ShengSet;