www.gusucode.com > VC++宾馆管理系统(Access)程序 > VC++宾馆管理系统(Access)程序\code\UserData.cpp
// UersData.cpp: implementation of the UersData class. // Download by http://www.NewXing.com ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "UserData.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 ////////////////////////////////////////////////////////////////////// CUserData::CUserData() { } CUserData::~CUserData() { } BOOL CUserData::GetPassword(CString *UserName, CString *Password,int *Level) { //初始化Com对象 CoInitialize(NULL); try { //初始化数据库连接对象 _ConnectionPtr pConn("ADODB.Connection"); //定义数据库连接字符串 _bstr_t Connection ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\HotelManageSys.mdb;Persist Security Info=False"; //打开数据库连接 pConn->Open(Connection, "", "", adConnectUnspecified); //初始化记录集对象 _RecordsetPtr pRs("ADODB.Recordset"); CString strSQL; strSQL.Format("%s\"%s\"", "Select * From UserInformation Where Name 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(255), _bstr_t(pRs->GetCollect("Pwd"))); *Level = pRs->GetCollect("Level").lVal; pRs->Close(); pRs.Release(); //关闭数据库连接 pConn->Close(); pConn.Release(); UserName->ReleaseBuffer(); Password->ReleaseBuffer(); return TRUE; } } catch(_com_error &e) { ::CoUninitialize(); ::AfxMessageBox(e.ErrorMessage()); return FALSE; } }