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

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