MFC 关于ADO连接数据库
BOOL CLibrary2App::InitInstance()
{
AfxEnableControlContainer();
ADOConn adoconn;
CloginDlg mydlg;
if(mydlg.DoModal()==IDOK)
{
CString sqlstr;
try
{
sqlstr.Format("select* from useinfo where user='%s'and password='%s'",mydlg.m_id,mydlg.m_password);
_bstr_t vSQL;
vSQL=(_bstr_t)sqlstr;
_RecordsetPtr m_recordset;
m_recordset=adoconn.GetRecordSet(vSQL);
CString str1,str2;
str1=(LPCTSTR)(_bstr_t)(m_recordset->GetCollect("user"));
str2=(LPCTSTR)(_bstr_t)(m_recordset->GetCollect("password"));
str1.TrimRight();
str2.TrimRight();
if(str1==mydlg.m_id||str2==mydlg.m_password)
{
AfxMessageBox("登陆成功");
}
else
{
AfxMessageBox("登陆失败2");
return false;
}
}
catch(...)
{
AfxMessageBox("登陆失败3");
return false;
}
}
程序运行结果显示登录失败3 数据库连接正常的!指点下