#import "C:/program files/common files/System/ado/msado15.dll" no_namespace /
rename("EOF","EndOfFile") /
rename("LockTypeEnum","newLockTypeEnum")/
rename("DataTypeEnum","newDataTypeEnum")/
rename("FieldAttributeEnum","newFieldAttributeEnum")/
rename("EditModeEnum","newEditModeEnum")/
rename("RecordStatusEnum","newRecordStatusEnum")/
rename("ParameterDirectionEnum","newParameterDirectionEnum")
step 2:在APP类里添加3个全局变量,1个私有变量
m_iLoginCount int (密码错误次数)
m_pADOSet _RecordsetPtr (ado记录集)
m_sCurrentUser CString (当前用户)
ADOConn _ConnectionPtr (ado连接) 私有
step 3:初始化ADO 在APP::instance
Enable3dControls(); // Call this when linking to MFC statically
// Init Login Count
m_iLoginCount = 0;
// Create ADO Connection
if( FAILED(::CoInitialize(NULL)) )
{
AfxMessageBox("ADO Init failed");
return false;
}
try
{
ADOConn.CreateInstance(__uuidof(Connection));
ADOConn->Open("DSN=Hotel_MIS;Provider=MSDASQL","sa","", adConnectUnspecified);
}
// Catch Exceptions
catch(_com_error &e)
{
CString err;
err.Format("%s", (char*)(e.Description()) );
AfxMessageBox(err);
}
catch(...)
{
AfxMessageBox("Unknown Error...");
}
// Init ADO RecordSet
m_pADOSet.CreateInstance(__uuidof(Recordset));