VC++之数据库技术之用ADO连接Oracle数据库.pdf
文本预览下载声明
VC++ 之数据库技术之用 ADO 连接 Oracle 数据库
2011-02-02 20:34
转载自 xiaoxing2099
最终编辑 xiaoxing2099
一、创建对话框应用程序
二、编辑对话框资源
控件 ID 及标题
连接 ORACLE 数据库
IDC_QUERY 查询
三、添加变量、函数
1、添加变量
// BQuery.h : main header file for the BQUERY application
class CBQueryApp : public CWinApp
public:
_ConnectionPtr m_pConnection;
// BQueryDlg.h : header file
class CBQueryDlg : public CDialog
public:
CListCtrl m_ListCtrl;
_RecordsetPtr m_pRecordset;
a、添加消息响应函数
b、添加函数
四、添加代码
1、于 “stdafx.h文件内添加输入语句”
// stdafx.h : include file for standard system include files,
#include afxcmn.h // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#import C:\Program Files\Common Files\System\ADO\msado15.dll no_namespace
rename(EOF, adoEOF)
2 、于 “Resource.h文件内添加资源” “IDC_LIST_DB ”
#define IDC_QUERY 1000
#define IDC_LIST_DB 1001
3 、 于 “BQueryDlg.h 文件内添加外部变量”
// BQueryDlg.h : header file
// CBQueryDlg dialog
extern CBQueryApp theApp;
class CBQueryDlg : public CDialog
4 、添加函数代码
a、于 “BQuery.cpp文件内添加”
BOOL CBQueryApp::InitInstance() //初始化
{
AfxEnableControlContainer();
AfxOleInit();// 初始化 COM 库
/*********** 连接数据库 *******/
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance(ADODB.Connection);
if(SUCCEEDED(hr))
{
hr = m_pConnection-Open(Provider=MSDAORA.1;Password=bank;User ID=bank;Data
Source=users;Persist Security Info=True,,,NULL);
}
}
catch(_com_error e)// 捕捉异常
{
CString errormessage;
errormessage.Format( 连接数据库失败 !\r\n 错误信息 :%s,e.ErrorMessage());
errormessage=请加入 Oracle 文件 ;
AfxMessageBox(errormessage);// 显示错误
显示全部