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();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值