ADO 数据库

我现正在做一个“银行储蓄系统管理”的程序设计。系统的添加和删除用户名,我都做好了,可是到了修改用户密码时,总是做不出来。我是以管理员的身份去修改用户的密码。用户表中有:账号、用户密码、存款人姓名,住址,存款日期等属性。我用来实现修改密码的VC++代码如下(也就是“确定”按钮函数里的代码):(不知道是哪里错了,麻烦各位指点指点。)

void CCHANGEPSW::OnOK() 
{
// TODO: Add extra validation here
  _variant_t var1,var;  
//从ADO记录集中得到的数据,其类型都是variant,_variant_t 是用于COM的variant的封装类
//CBank1App * ptheApp = (CBank1App *) AfxGetApp();
CString str,strpwd,strname; 
UpdateData(TRUE);
  m_new_password.TrimRight();
m_confirm_password.TrimRight();
m_old_password.TrimRight();
m_user_Bno.TrimRight();

  // m_pUserRecordset.CreateInstance(__uuidof(Recordset));因为在BOOL CCHANGEPSW::OnInitDialog()中已经打开了。
  if(m_user_Bno!=""&&!m_pUserRecordset->adoBOF)
{
while(!m_pUserRecordset->adoEOF) //用于查找用户名是否存在
{
m_pUserRecordset->MoveFirst();
var = m_pUserRecordset->GetCollect("Bno");
strname=(LPCSTR)_bstr_t(var);
strname.TrimRight();
if(m_user_Bno == strname) break;
else
m_pUserRecordset->MoveNext();
}
  if(m_pUserRecordset->adoEOF)
{
  AfxMessageBox("用户名不存在!");
return;
}
}
str.Format("select * from Buser where Bno='%s'",m_user_Bno);
//使用CString类成员初始化str字符串.
  // str.Format("select * from user_info where userName='"+theApp.current_username+"'");
//使用CString类成员初始化str字符串.
  try
{
m_pUserRecordset->Open(str.AllocSysString(),
//将字符串变量str从CString类型转换为BSTR类型 
//BSTR类型是COM编程使用的字符串类型
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}

if(m_user_Bno=="")  
{
AfxMessageBox("请输入要修改的用户名!");
return;
}

if(!m_pUserRecordset->adoEOF)
{
var1=m_pUserRecordset->GetCollect("Bpassword");
  strpwd=(LPCSTR)_bstr_t(var1);
  strpwd.TrimRight();
if(m_old_password=="")
{
AfxMessageBox("请输入旧密码!");
return;
}
if(strpwd!=m_old_password)
{
AfxMessageBox("输入的旧密码不对!");
m_new_password="";
  m_confirm_password="";
  m_old_password="";
UpdateData(FALSE);
  return;
}
if(m_new_password=="")  
{
AfxMessageBox("请输入新密码!");
return;
}
if(m_confirm_password=="")  
{
AfxMessageBox("请输入确认密码!");
return;
}
if(m_new_password!=m_confirm_password)
{
m_new_password="";
m_confirm_password="";
UpdateData(false); 
AfxMessageBox("两次密码输入不同,请再次输入!");
return;  
}
else
{
 
str.Format("update Buser set Bpassword='%s' where Bno='%s'",m_new_password,m_user_Bno);
try
{
m_pUserRecordset->Open( str.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
AfxMessageBox("密码修改成功!");
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}

}
}
  }
//CDialog::OnOK();
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章