如果SQL语句以前成功执行过,第二次执行过程会不会再访问数据库,该如何处理
如果SQL语句以前成功执行过,第二次执行过程会不会再访问数据库
我做的登陆界面很奇怪,没有的用户是无法登陆的,但是一旦登陆成功,即使删除了该用户,该用户还可以登录,下面是登陆界面的代码:
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
{
pMsg->wParam = 9;
}
if(pMsg->message == WM_LBUTTONDOWN)
{
CRect rect,rc;
m_ok.GetWindowRect(&rect);
m_cancel.GetWindowRect(&rc);
CPoint point;
GetCursorPos(&point);
if(rect.PtInRect(point))
{
UpdateData(TRUE);
if(m_name.IsEmpty() || m_pwd.IsEmpty())
{
MessageBox("用户名或密码不能为空");
return FALSE;
}
m_time++;
try
{
//创建连接对象实例
m_pConnection.CreateInstance(__uuidof(Connection));
//使用Open方法连接数据库
m_pConnection->Open("Provider=MSDASQL.1;Persist Security Info=False;Data Source=MS Access Database;","","",adConnectUnspecified);
}
catch(_com_error e)
{
CString strError;
strError.Format("警告打开异常,错误信息:%s",e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
CString sql;
try
{
sql.Format("select * from users where id= '%s' and pwd = '%s'",
m_name,m_pwd);
m_pRecordset = m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
}
catch(_com_error e)
{
CString strError;
strError.Format("警告打开异常,错误信息:%s",e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
CString str;
if(!m_pRecordset->adoEOF)
{
str=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("posi");
if(str=="1")
{
SendMessage(WM_CLOSE);
CAdmin dlg;
dlg.DoModal();
CDialog::OnOK();
}
if(str=="2")
{
CMast dlg;
dlg.DoModal();
CDialog::OnOK();
}
/* if(str=="3")
{
CADMIN dlg;
dlg.DoModal();
CDialog::OnOK();
}
if(str=="4")
{
CADMIN dlg;
dlg.DoModal();
CDialog::OnOK();
}*/
}
else
{
if(m_time == 3)
{
MessageBox("密码3次不正确");
CDialog::OnCancel();
}
else
{
AfxMessageBox(" 用户名或密码不正确!!! ");
m_name = "";
m_pwd = "";
UpdateData(FALSE);
}
}
//if(m_pRecordset!=NULL)
m_pRecordset->Close();
m_pRecordset.Release();
m_pConnection->Close();
}
if(rc.PtInRect(point))
{
CDialog::OnCancel();
}
}
return CDialog::PreTranslateMessage(pMsg);
}
------解决方案--------------------
1.删掉用户后确保没有这个用户记录了
2.确保内存中没有这个用户,你要不重新打开软件再登录试试
------解决方案--------------------
因为你是直接从数据库中查找,因此跟缓存应该是没有关系的
我做的登陆界面很奇怪,没有的用户是无法登陆的,但是一旦登陆成功,即使删除了该用户,该用户还可以登录,下面是登陆界面的代码:
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
{
pMsg->wParam = 9;
}
if(pMsg->message == WM_LBUTTONDOWN)
{
CRect rect,rc;
m_ok.GetWindowRect(&rect);
m_cancel.GetWindowRect(&rc);
CPoint point;
GetCursorPos(&point);
if(rect.PtInRect(point))
{
UpdateData(TRUE);
if(m_name.IsEmpty() || m_pwd.IsEmpty())
{
MessageBox("用户名或密码不能为空");
return FALSE;
}
m_time++;
try
{
//创建连接对象实例
m_pConnection.CreateInstance(__uuidof(Connection));
//使用Open方法连接数据库
m_pConnection->Open("Provider=MSDASQL.1;Persist Security Info=False;Data Source=MS Access Database;","","",adConnectUnspecified);
}
catch(_com_error e)
{
CString strError;
strError.Format("警告打开异常,错误信息:%s",e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
CString sql;
try
{
sql.Format("select * from users where id= '%s' and pwd = '%s'",
m_name,m_pwd);
m_pRecordset = m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
}
catch(_com_error e)
{
CString strError;
strError.Format("警告打开异常,错误信息:%s",e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
CString str;
if(!m_pRecordset->adoEOF)
{
str=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("posi");
if(str=="1")
{
SendMessage(WM_CLOSE);
CAdmin dlg;
dlg.DoModal();
CDialog::OnOK();
}
if(str=="2")
{
CMast dlg;
dlg.DoModal();
CDialog::OnOK();
}
/* if(str=="3")
{
CADMIN dlg;
dlg.DoModal();
CDialog::OnOK();
}
if(str=="4")
{
CADMIN dlg;
dlg.DoModal();
CDialog::OnOK();
}*/
}
else
{
if(m_time == 3)
{
MessageBox("密码3次不正确");
CDialog::OnCancel();
}
else
{
AfxMessageBox(" 用户名或密码不正确!!! ");
m_name = "";
m_pwd = "";
UpdateData(FALSE);
}
}
//if(m_pRecordset!=NULL)
m_pRecordset->Close();
m_pRecordset.Release();
m_pConnection->Close();
}
if(rc.PtInRect(point))
{
CDialog::OnCancel();
}
}
return CDialog::PreTranslateMessage(pMsg);
}
------解决方案--------------------
1.删掉用户后确保没有这个用户记录了
2.确保内存中没有这个用户,你要不重新打开软件再登录试试
------解决方案--------------------
因为你是直接从数据库中查找,因此跟缓存应该是没有关系的