📄 vchelpe1.cpp
字号:
// vchelpDoc.cpp : implementation of the CVchelperDoc class
//
#include "stdafx.h"
#include "vchelper.h"
#include "vchelperDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVchelperDoc
IMPLEMENT_DYNCREATE(CVchelperDoc, CDocument)
BEGIN_MESSAGE_MAP(CVchelperDoc, CDocument)
//{{AFX_MSG_MAP(CVchelperDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVchelperDoc construction/destruction
CVchelperDoc::CVchelperDoc()
{
// TODO: add one-time construction code here
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
CString str="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+theApp.m_Dbname;
hr = m_pConnection->Open((_bstr_t)str,"","",adModeUnknown);///连接数据库
///上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51;
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}
m_pTypeset.CreateInstance("ADODB.Recordset");
m_pDataset.CreateInstance("ADODB.Recordset");
}
CVchelperDoc::~CVchelperDoc()
{
if(m_pTypeset->State==1)
m_pTypeset->Close();
if(m_pDataset->State==1)
m_pDataset->Close();
m_pConnection->Close();
}
BOOL CVchelperDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
((CEditView*)m_viewList.GetHead())->SetWindowText(NULL);
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CVchelperDoc serialization
void CVchelperDoc::Serialize(CArchive& ar)
{
// CEditView contains an edit control which handles all serialization
((CEditView*)m_viewList.GetHead())->SerializeRaw(ar);
}
/////////////////////////////////////////////////////////////////////////////
// CVchelperDoc diagnostics
#ifdef _DEBUG
void CVchelperDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CVchelperDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CVchelperDoc commands
void CVchelperDoc::UpdataDb()
{
if(m_pConnection->State==1)
m_pConnection->Close();
HRESULT hr;
try
{
CString str="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+theApp.m_Dbname;
hr = m_pConnection->Open((_bstr_t)str,"","",adModeUnknown);///连接数据库
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -