📄 dataservice_access.cpp
字号:
// DataService_Access.cpp: implementation of the DataService_Access class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Login.h"
#include "DataService_Access.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//导入ADO类型库
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "ENDOFFILE")
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DataService_Access::DataService_Access()
{
}
DataService_Access::~DataService_Access()
{
}
bool DataService_Access::GetPassword(CString *UserName, CString *Password)
{
//初始化Com对象
CoInitialize(NULL);
try
{
//初始化数据库连接对象
_ConnectionPtr pConn("ADODB.Connection");
//打开数据库连接
//注意:下面这条语句中的字符串应该在同一行上,中间不能有回车,本书为了排版方便而增加
//了回车符。
pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Demo.mdb;Persist Security Info=False", "", "", adConnectUnspecified);
//初始化记录集对象
_RecordsetPtr pRs("ADODB.Recordset");
CString strSQL;
strSQL.Format("%s\"%s\"", "Select * From UserInfo Where UserName like ", UserName->GetBuffer(UserName->GetLength()));
//打开指定记录集
pRs->Open(_variant_t(strSQL.GetBuffer(strSQL.GetLength())), _variant_t(pConn, true), adOpenStatic, adLockOptimistic, adCmdText);
//访问记录集中数据
if (pRs->BOF)
{
//关闭记录集
pRs->Close();
pRs.Release();
//关闭数据库连接
pConn->Close();
pConn.Release();
UserName->ReleaseBuffer();
Password->ReleaseBuffer();
return false;
}
else
{
strcpy(Password->GetBuffer(11), _bstr_t(pRs->GetCollect("Password")));
pRs->Close();
pRs.Release();
//关闭数据库连接
pConn->Close();
pConn.Release();
UserName->ReleaseBuffer();
Password->ReleaseBuffer();
return true;
}
}
catch(_com_error &e)
{
CoUninitialize();
::AfxMessageBox(e.ErrorMessage());
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -