下载 ado2.h和ado2.cpp文件
在VC++ 目录-->包含目录 -->添加 msado15.dll, msjro.dll 目录。
// TODO: 连接sqlserver, 在stdafx.h 中定义这些,#define _BS_DLL_EXPORT_# ifdef _BS_DLL_EXPORT_ # define BS_DLL_EXPORT __declspec(dllexport) # else# define BS_DLL_EXPORT __declspec(dllimport) # endif
连接sqlserver数据库bool connectToSqlServer()
{
CADODatabase *g_pAdoDatabase; try{ if (g_pAdoDatabase == NULL)
g_pAdoDatabase = new CADODatabase();
CString strConnString = "Provider=SQLOLEDB;Persist Security Info=False;Data Source=" + \
strServer + ";Initial Catalog=" + strDatabase + ";User Id=" + strUser + ";Password=" + strPwd;
g_pAdoDatabase->SetConnectionString((LPCTSTR)strConnString);
} catch (...)
{ return false;
} return true;
}
if(g_pAdoDatabase->Open())
{ // 查询
CString sqlText = "select ...";
CADORecordset* pRs = new CADORecordset(g_pAdoDatabase); if(pRs->Open((LPCTSTR)sqlText))
{ while (!pRs->IsEof())
{
pRs->GetFieldValue("id", ID);
pRs->MoveNext();
}
}
pRs->Close();
delete pRs;
}catch (...)
{
return false;
}if(g_pAdoDatabase->IsOpen())
{
g_pAdoDatabase->Close();
}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号