God horse also did not say, directly to the source code and engineering
The principle of this thing Google under, are out, they say as a novice,
1 should print out, link error reason
2 The database should be placed under the project, paying special attention to this
Give some of the source code, you can also go to see my upload project
StdAfx.h
StdAfx.h: Standard system contains file containing files,//or frequently used but infrequently changed//project-specific include files #pragma once#ifndef _secure_atl#define _secure_atl 1#endif# Ifndef vc_extralean#define Vc_extralean//exclude rarely used data from the Windows header #endif#include "targetver.h" #define _atl_cstrin G_explicit_constructors///Some CString constructors will be explicit//Shut down MFC's hidden # define _afx_all_warnings#include for some common but often reassuring warning messages <a Fxwin.h>//MFC core components and standard components # include <afxext.h>//MFC extensions # include <afxdisp.h>//MFC Automatic Class #ifndef _afx_no_ole_support#include <afxdtctl.h>//MFC support for Internet Explorer 4 common Controls #endif#ifndef _afx_ No_afxcmn_support#include <afxcmn.h>//MFC support for Windows Common Controls #endif//_afx_no_afxcmn_support#include &L T;afxcontrolbars.h>///Ribbon and Control bar MFC support # include <afxdb.h> #ifdef _unicode#if defined _m_ix86#pragma Comment (lin Ker, "/manifestdependency:\" Type= ' Win32 ' Name= ' Microsoft.windows.common-controls ' version= ' 6.0.0.0 ' Processorarchitecture= ' x86 ' publickeytoken= ' 6595b64144CCF1DF ' language= ' * ' "") #elif defined _m_x64#pragma COMMENT (linker, "/manifestdependency:\" Type= ' Win32 ' Name= ' Microsoft.windows.common-controls ' version= ' 6.0.0.0 ' processorarchitecture= ' amd64 ' publickeytoken= ' 6595B64144CCF1DF ' language= ' * ' "") #else #pragma comment (linker, "/manifestdependency:\" Type= ' Win32 ' Name= ' Microsoft.windows.common-controls ' version= ' 6.0.0.0 ' processorarchitecture= ' * ' publickeytoken= ' 6595b64144ccf1df ' Language= ' * ' "")/* #import "c:\program Files\Common Files\system\ado\msado15.dll" No_namespace rename ("EOF", "adoeof" ) using namespace adodb;*/#endif #import "C:\Program Files\Common Files\system\ado\msado15.dll" No_namespace rename (" EOF "," adoeof ") Rename (" BOF "," Adobof ")//using namespace ADODB; #endif
Link code. cpp
MfcLinkAccess.cpp: Defines the class behavior of the application. #include "stdafx.h" #include "mfcLinkAccess.h" #include "mfcLinkAccessDlg.h" #ifdef _debug#define new Debug_new#endif Cmfclinkaccessappbegin_message_map (Cmfclinkaccessapp, CWinApp) on_command (Id_help, &cwinapp::onhelp) END_ Message_map ()//Cmfclinkaccessapp construct Cmfclinkaccessapp::cmfclinkaccessapp () {//Support restart Manager m_ Dwrestartmanagersupportflags = afx_restart_manager_support_restart;//TODO: Add construction code here,//Place all important initializations in InitInstance} The only one Cmfclinkaccessapp object Cmfclinkaccessapp theapp;//Cmfclinkaccessapp initialize bool Cmfclinkaccessapp::initinstance () { If an application manifest that is running on Windows XP specifies that you want//use ComCtl32.dll version 6 or later to enable visualization,//Requires Initcommoncontrolsex (). Otherwise, the window cannot be created. AfxEnableControlContainer ();//Add the Initialize ole/com Environment code if (! AfxOleInit ()) {AfxMessageBox (_t ("Initialize OLE DLL failed!")); return FALSE; HRESULT hr =:: CoInitialize (NULL); if (! SUCCEEDED (HR)) {AfxMessageBox (_t ("Initial exchange COM failure"));///Display error message}_connectionptr m_pconnection;//_bstr_t strconnect ( strconnction); try{hr = M_pconnection.createInstance (__uuidof (Connection));///Create Connection object; if (SUCCEEDED (HR)) {hr = M_pconnection->open ("provider= Microsoft.ace.oledb.12.0;data Source=demo.mdb; Persist Security Info=false "," "," ", admodeunknown);///Connection Database///The provider in the connection string in the above sentence is for ACCESS2000 environment, for ACCESS97,// Need to change to: Provider=microsoft.jet.oledb.3.51;//afxmessagebox (_t ("Link succeeded! "));}} catch (_com_error e) {CString errormessage; ErrorMessage. Format (_t ("Connection database failed!\r\n error message:%s"), E.errormessage ()); AfxMessageBox (errormessage)/////Display error message AfxMessageBox (E.description ());///Display error message return-1;} Initcommoncontrolsex initctrls;initctrls.dwsize = sizeof (initctrls);//Set it to include all//common control classes to be used in the application. INITCTRLS.DWICC = Icc_win95_classes;initcommoncontrolsex (&initctrls); CWinApp::InitInstance (); AfxEnableControlContainer ();//Create Shell Manager in case the dialog box contains//any Shell tree view control or Shell List view control. CShellManager *pshellmanager = new cshellmanager;//standard initialization//If these features are not used and you want to reduce//final executable size, remove the following//unwanted specific initialization routines// Change the registry key used to store settings//TODO: The string should be modified appropriately,//For example, to the company or organization name Setregistrykey (_t ("Application wizard generatedLocal application ")); Cmfclinkaccessdlg Dlg;m_pmainwnd = &dlg;int_ptr Nresponse = dlg. DoModal (); if (nresponse = = IDOK) {//TODO: The code in this place processing when//"OK" to close the dialog box}else if (nresponse = = IDCANCEL) {//TODO: When to place processing in// Cancel to close the Code for the dialog box}//Delete the shell manager created above. if (Pshellmanager! = NULL) {delete Pshellmanager;} Because the dialog box is closed, FALSE is returned to exit the application,//instead of starting the application's message pump. return FALSE;}
Download my project before you know it!
MFC links Access 2007 databases