程序如下:
//修改口令对话框
void CModPswdDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE); //将对话框的数据付给变量
_variant_t strQuery;
strQuery="select * from useraccount\
where username='"+m_strUser+"'and password='"+m_strOldps+"'";
theApp.ADOExecute(theApp.m_pADOSet,strQuery); //打开记录机集
if(theApp.m_pADOSet->GetRecordCount()==1)
{
if(m_strNewps=m_strConfirmps) //如果用户名,原密码输入正确且新口令与确认口令相同则修改成功
{
strQuery="Update useraccount set username="+m_strUser+",password="+m_strNewps+"";
if(theApp.ADOExecute(theApp.m_pADOSet,strQuery))
{
AfxMessageBox(_T("修改口令成功!"),MB_ICONINFORMATION);
CDialog::OnOK();
}
else
{
AfxMessageBox(_T("修改口令失败!"),MB_ICONINFORMATION);
m_strNewps=m_strConfirmps="";
UpdateData(FALSE);
}
}
else //否则,提醒新密码确认错误
{
AfxMessageBox(_T("新密码确认错误!"),MB_ICONINFORMATION);
m_strNewps=m_strConfirmps="";
UpdateData(FALSE);
}
}
else //如果不相同,看是用户名错误还是原密码错误
{
strQuery="select * from useraccount where username='"+m_strUser+"'";
theApp.ADOExecute(theApp.m_pADOSet,strQuery);
if(theApp.m_pADOSet->GetRecordCount()==0)
{
AfxMessageBox(_T("用户名输入不正确!"),MB_ICONINFORMATION);
m_strUser=m_strOldps=m_strNewps=m_strConfirmps="";
UpdateData(FALSE);
}
else
{
AfxMessageBox(_T("原口令不正确!"),MB_ICONINFORMATION);
m_strOldps=m_strNewps=m_strConfirmps="";
UpdateData(FALSE);
}
}
if(theApp.m_pADOSet->GetState()==adStateOpen)theApp.m_pADOSet->Close();
}
调试时,用户名密码输入a,a(数据库已有)当所有都正确时出现
ADO Error:[Microsoft][ODBC SQL Server Driver][SQL Server]列名'a'无效。
//修改口令对话框
void CModPswdDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE); //将对话框的数据付给变量
_variant_t strQuery;
strQuery="select * from useraccount\
where username='"+m_strUser+"'and password='"+m_strOldps+"'";
theApp.ADOExecute(theApp.m_pADOSet,strQuery); //打开记录机集
if(theApp.m_pADOSet->GetRecordCount()==1)
{
if(m_strNewps=m_strConfirmps) //如果用户名,原密码输入正确且新口令与确认口令相同则修改成功
{
strQuery="Update useraccount set username="+m_strUser+",password="+m_strNewps+"";
if(theApp.ADOExecute(theApp.m_pADOSet,strQuery))
{
AfxMessageBox(_T("修改口令成功!"),MB_ICONINFORMATION);
CDialog::OnOK();
}
else
{
AfxMessageBox(_T("修改口令失败!"),MB_ICONINFORMATION);
m_strNewps=m_strConfirmps="";
UpdateData(FALSE);
}
}
else //否则,提醒新密码确认错误
{
AfxMessageBox(_T("新密码确认错误!"),MB_ICONINFORMATION);
m_strNewps=m_strConfirmps="";
UpdateData(FALSE);
}
}
else //如果不相同,看是用户名错误还是原密码错误
{
strQuery="select * from useraccount where username='"+m_strUser+"'";
theApp.ADOExecute(theApp.m_pADOSet,strQuery);
if(theApp.m_pADOSet->GetRecordCount()==0)
{
AfxMessageBox(_T("用户名输入不正确!"),MB_ICONINFORMATION);
m_strUser=m_strOldps=m_strNewps=m_strConfirmps="";
UpdateData(FALSE);
}
else
{
AfxMessageBox(_T("原口令不正确!"),MB_ICONINFORMATION);
m_strOldps=m_strNewps=m_strConfirmps="";
UpdateData(FALSE);
}
}
if(theApp.m_pADOSet->GetState()==adStateOpen)theApp.m_pADOSet->Close();
}
调试时,用户名密码输入a,a(数据库已有)当所有都正确时出现
ADO Error:[Microsoft][ODBC SQL Server Driver][SQL Server]列名'a'无效。
strQuery="Update useraccount set username="+m_strUser+",password="+m_strNewps+"";
if(theApp.ADOExecute(theApp.m_pADOSet,strQuery))
{
AfxMessageBox(_T("修改口令成功!"),MB_ICONINFORMATION);
CDialog::OnOK();
}
(theApp.ADOExecute(theApp.m_pADOSet,strQuery); //打开记录机集)
调试时,用户名密码输入a,a(数据库已有)当所有都正确时出现
ADO Error:[Microsoft][ODBC SQL Server Driver][SQL Server]列名'a'无效。