C++ 中的数据库访问
Database access in c++
当我编译这个程序时,
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <afxdb.h>
#define _AFXDLL
int main(int argc, char *argv[])
{
CString sDsn;
CDatabase db;
sDsn = "ODBC; DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; DSN = ''; DBQ = D:DATABASEbible.mdb";
db.Open(NULL, false, false, sDsn);
try
{
CRecordset rs(&db);
CString strOut;
CString strOut2;
CString strOut3;
CString SqlString = "SELECT nom_prophete FROM L_PROPHETE";
rs.Open(CRecordset::snapshot, SqlString, CRecordset::appendOnly);
rs.GetFieldValue((short)0, strOut);
AfxMessageBox(strOut);
// --- petite transformation en string
// --- pour l'affichage sur la console
CT2CA pszConvertedAnsiString(strOut);
std::string strStd(pszConvertedAnsiString);
std::cout << "--" << strStd.c_str() << std::endl;
rs.MoveNext();
// --- petite transformation en string
// --- pour l'affichage sur la console
CT2CA pszConvertedAnsiString2(strOut2);
std::string strStd2(pszConvertedAnsiString2);
std::cout << "--" << strStd2.c_str() << std::endl;
rs.MoveNext();
rs.GetFieldValue((short)0, strOut3);
AfxMessageBox(strOut3);
// -- petite transformation en string
// -- pour l'affichage sur la console
CT2CA pszConvertedAnsiString3(strOut3);
std::string strStd3(pszConvertedAnsiString3);
std::cout << "--" << strStd3.c_str() << std::endl;
rs.Close();
}
catch (CDBException *p)
{
AfxMessageBox(p->m_strError);
}
return 0;
}
它显示此错误,
Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] c:program files (x86)microsoft visual studio 12.0vcatlmfcincludeafx.h 24 1 MA_BIBLE
*/
转到"
项目设置"-">配置属性"->"常规",并确保为调试版本和发布版本设置"在共享 DLL 中使用 MFC"。
此外,如果您在某处包含 windows.h - 删除该行,因为 MFC 项目应仅包含 afxwin.h
相关文章:
- 使用 Qt5 SQL 进行异步数据库访问的策略
- 根据用户名和密码 Qt C++重新访问数据库值
- 缓存和访问数据库数据的有效方法?
- 可以删除SQLite3数据库文件,并且仍然可以访问
- 没有绝对路径无法访问数据库
- 使用连接器 c++ 访问 MYSQL 数据库(如何将路径添加到我的标准搜索目录)
- 访问数据库-QODBC驱动程序在管理员上执行授予
- 如何从Qt使用密码访问Sqlite数据库
- 如何为数据库设置密码,以便没有人可以访问它
- 如何使用QT/C 中的多线程用API访问我的数据库
- 数据库访问对象设计模式
- SQLite C++多个进程以只读模式访问数据库时"数据库已锁定"
- 仅使用一个用户id和密码访问数据库
- Okcupid.com(无需访问数据库即可查找匹配项!?)
- C++/MySQL - 通过主机地址访问数据库时'Unknown MySQL server host';没有 IP
- 使用线程访问数据库
- 在并行线程中访问数据库,可行的选项
- 无需安装即可访问C++数据库
- Quora和Facebook使用哪些C++库来访问数据库
- 两个函数同时访问数据库