请教各位ado编程菜鸟问题
想编写一个用ADO来访问数据库的程序,但不知到错误在那里,请教给位高手,谢谢!
----------- STDAFX.H
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__B4B11017_5F87_4732_8F84_BDA823C53394__INCLUDED_)
#define AFX_STDAFX_H__B4B11017_5F87_4732_8F84_BDA823C53394__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#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 // _AFX_NO_AFXCMN_SUPPORT
//peter add begin
#include <comdef.h>
#pragma warning(disable:4146)
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF","adoEOF")
#pragma warning(default:4146)
//#include "adoid.h"
//#include "adoint.h"
//#include "icrsint.h"
//peter add end
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__B4B11017_5F87_4732_8F84_BDA823C53394__INCLUDED_)
----------- ADOTESTDLG.CPP
BOOL CAdoTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//peter add begin
try{
m_pConnection.CreateInstance(__uuidof(Connetion));
m_pConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\GCL6\\Data\\Test.mdb;",
"","",-1); //在"="两边莫加空格!
catch(...)
{
AfxMessageBox("数据库连接失败!");
}
//peter add end
return TRUE; // return TRUE unless you set the focus to a control
}
错误提示:
--------------------Configuration: AdoTest - Win32 Debug--------------------
Compiling...
AdoTestDlg.cpp
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(122) : error C2065: 'Connetion' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(123) : error C2039: 'Open' : is not a member of '_com_ptr_t<class _com_IIID<struct _Connection,&struct __s_GUID _GUID_00000550_0000_0010_8000_00aa006d2ea4> >'
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(125) : error C2318: no try block associated with this catch handler
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(133) : error C2317: 'try' block starting on line '121' has no catch handlers
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(134) : error C2601: 'OnSysCommand' : local function definitions are illegal
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(151) : error C2601: 'OnPaint' : local function definitions are illegal
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(178) : error C2601: 'OnQueryDragIcon' : local function definitions are illegal
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(183) : error C2601: 'OnInitDialog' : local function definitions are illegal
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(251) : error C2601: 'OnButton1' : local function definitions are illegal
C:\Documents and Settings\Administrator\桌面\3\AdoTest\AdoTestDlg.cpp(258) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
AdoTest.exe - 10 error(s), 0 warning(s)