求助,如何用VC连接Acess2000?谢谢
解决方案 »
- “atof”: 不能将参数 1 从“LPCTSTR”转换为“const char *”
- 如何通过按钮点击事件切换formview
- 请教gethostbyaddr
- 如何读入一个UNICODE编码格式的汉字符?我的VC是ANSI编译的。
- 关于如何制作协议安装程序
- 使用Media Player控件的问题!救命啊!
- 在线等,关于汉字转化成十六进制(pc机中数据库中的中文信息要输入到ic卡)!!!
- 急,在线等待:RELEASE 下的调试错误
- 哪儿有关于ADO和树控件的运用的网上资源?
- win8平板Win32API捕获指南针磁北读数不正确
- 高分求救,请问用DAO访问Access时,可以用两个不同的对象读同一个表吗?
- 帮忙 谁有漂亮的开关位图 急
CString szConnect;
szConnect.Format("ODBC;DRIVER={Microsoft Excel Driver (*.xls)};DSN='';DBQ=%s", m_strArray->GetAt(0));
CDatabase db;
try
{
db.Open("", FALSE, TRUE, szConnect);
}
catch (CException *e)
{
e->ReportError();
e->Delete();
}
m_pDatabase = new CDaoDatabase;
try
{
m_pDatabase->Open("db.mdb");
m_pRecordset = new CDaoRecordset(m_pDatabase);
}
catch (CDaoException* e)
{
e->ReportError();
delete m_pDatabase;
m_pDatabase = NULL;
e->Delete();
return;
}
我用这个总是不行,错在哪里
1)用access把access2000格式的数据库转换为access97的库。
2)在vc程序里边加入一行语句,具体如下:
To read Access 2000mdb, i added the following code :
AfxGetModuleState()->m_dwVersion = 0x0601;
and then i could read Access 2000 mdb,
Your project config must be set to shared dll
Insert into the initinstance of your myprojapp.h file as
shown below
[ccode]
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
AfxGetModuleState()->m_dwVersion = 0x0601;
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically'
#endif
[/ccode]
Hope that helps
The information in this article applies to:
Microsoft Visual C++, 32-bit Enterprise Edition 6.0
Microsoft Visual C++, 32-bit Professional Edition 6.0
Microsoft Visual C++, 32-bit Learning Edition 6.0This article was previously published under Q236991
SYMPTOMS
When opening a database created with Access 2000 through MFC DAO classes in Visual C++, you get the following error message: Unrecognized database format.
You also get this message when trying to create a new MFC DAO database SDI or MDI project using MFC AppWizard.
CAUSE
This error message occurs because the MFC DAO classes that ship with Visual C++ 6.0 load DAO 3.5 (Dao350.dll) by default. DAO 3.5 uses Jet 3.5, which can only open Jet 3.5 format (or earlier) databases. Access 2000 creates Jet 4.0 format database files, which are unrecognizable to Jet 3.5. To successfully open an Access 2000 database using the MFC DAO classes, you need to use DAO 3.6 (Dao360.dll). DAO 3.6 uses Jet 4.0, which can open any available Access database format.
RESOLUTION
Currently, there is no workaround to using AppWizard with Access 2000 data sources.For your application to use version 3.6 of DAO, you must update the version of MFC at run time to MFC version 6.01. To do this depends on whether you are building the application to use the MFC DLL or to build with the static libraries for MFC. If you are linking with the MFC DLL, you can specify that you want MFC to use DAO 3.6 by inserting the following line of code before you open an Access 2000 database:
AfxGetModuleState()->m_dwVersion = 0x0601;
Insert this line in the CYourApp::Initinstance() function of your program. If you are building with the static MFC libraries, following are the steps to get static builds of MFC to use DAO 3.6:
Modify the Daocore.cpp file in the MFC SRC directory. You will receive the following comment:// Determine whether to use DAO 3.6, 3.5, or 3.0
// Use DAO 3.0 if DLL build and not built with MFC 4.21 or later
// Use DAO 3.6 if MFC 6.01 or later
// otherwise, DAO 3.5
Add the following lines:#undef _MFC_VER
#define _MFC_VER 0x0601
Rebuild the library for the variant you need. For example, to build the static MFC library, debug version, non-Unicode, with no browser files use the following command at the command prompt in the MFC\SRC folder:
nmake DEBUG=1for release:
nmake DEBUG=0for unicode builds:
nmake DEBUG=1 UNICODE=1
nmake DEBUG=0 UNICODE=1
NOTE: You need to make certain that the compiler tools are in your path. If not, you may need to run the Vcvars32.bat file located in the Visual C++ \BIN folder. Also note that when you build these new versions of the libraries, they will be copied over the top of the existing ones in the MFC\LIB folder so you may want to save the old ones first.
STATUS
This behavior is by design.