主题:书上的例题,光盘上的源码,不知为何有Runtime errors?
#include "stdafx.h"
#include "Example26.h"
[color=C0C0C0][color=FF0000][color=0000FF]#include "afxdao.h"[/color][/color][/color]
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
[color=0000FF]AfxGetModuleState()->m_dwVersion = 0x0601;
AfxDaoInit();
CDaoDatabase m_MyDatabase;
m_MyDatabase.Open("mytest.mdb");
printf("tables'count: %d\n",m_MyDatabase.GetTableDefCount());
LPCTSTR str_SQL="Create Table table2(test1 Text(10),test2 Short)";
m_MyDatabase.Execute(str_SQL);
m_MyDatabase.Close();
m_MyDatabase.Open("mytest.mdb");
printf("tables'Count: %d\n",m_MyDatabase.GetTableDefCount());
LPCTSTR str_Drop="Drop table table2";
m_MyDatabase.Execute(str_Drop);
m_MyDatabase.Close();[/color] }
getchar();
return nRetCode;
}
[color=FF0000]数据库有连接好,table2无重名[/color]
#include "Example26.h"
[color=C0C0C0][color=FF0000][color=0000FF]#include "afxdao.h"[/color][/color][/color]
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
[color=0000FF]AfxGetModuleState()->m_dwVersion = 0x0601;
AfxDaoInit();
CDaoDatabase m_MyDatabase;
m_MyDatabase.Open("mytest.mdb");
printf("tables'count: %d\n",m_MyDatabase.GetTableDefCount());
LPCTSTR str_SQL="Create Table table2(test1 Text(10),test2 Short)";
m_MyDatabase.Execute(str_SQL);
m_MyDatabase.Close();
m_MyDatabase.Open("mytest.mdb");
printf("tables'Count: %d\n",m_MyDatabase.GetTableDefCount());
LPCTSTR str_Drop="Drop table table2";
m_MyDatabase.Execute(str_Drop);
m_MyDatabase.Close();[/color] }
getchar();
return nRetCode;
}
[color=FF0000]数据库有连接好,table2无重名[/color]