请哪位老大帮帮忙,赋值的问题。烦死了,找不到人问!

lm9764 2002-09-29 03:29:24
我有一个数据库表中有三项,我在一个对话框的ListBox把它的姓名显示出来。
显示时我引用一个工具类CUser(CListBox类)每当在ListBox 中插入一个数据就会创建一个User对象,而列表框中的每项数据指向以一个保存User数据User对象
然后我又添加三个文本框可以通过它修改数据库。但是这三个文本框的数据传不到
*pUser娜为老大可以帮我解决以下问题?????????????????
BOOL CUserMaintenanceDlg::GetSelectedUser(int *piIndex,User**ppUser)
{
BOOL bSuccess = false;
int iIndex;
if(LB_ERR!=(iIndex = m_lbxUsers.GetCurSel()))
{
*piIndex = iIndex;


*ppUser = (User*)m_lbxUsers.GetItemData(iIndex);
bSuccess = true;
UpdateData(false);
}
return bSuccess;
}

void CUserMaintenanceDlg::OnButton1()
{
// TODO: Add your control notification handler code here
int iCurrIndex;

User *pUser = NULL;
if(GetSelectedUser(&iCurrIndex,&pUser))
{
ASSERT(pUser);
if(pUser)
{
UpdateData();
CString strPrevUserID;
strPrevUserID = m_strUserID;
CString strPrevUserName;
strPrevUserName = m_strUserName;
int iPrevStatus = m_iStatus;
就是这一部分值传不过来???
// pUser->m_strUserID = m_strUserID;
pUser->m_strUserName = m_strUserName;
pUser->m_iStatus = m_iStatus; } //就是这一部分值传不过来???
if(SaveUser(pUser))
{
if(LB_ERR==m_lbxUsers.DeleteString(iCurrIndex))
{
AfxMessageBox("The User ID was Saved,""but the previous User ID coule not be ""removed from the listbox.");
}

else
{
int iNewIndex = m_lbxUsers.AddString(pUser->m_strUserName);
if((LB_ERR== iNewIndex)||(LB_ERRSPACE== iNewIndex))
{
AfxMessageBox("The User ID was Saved but" "the new user ID could" "not be added to the listbox.");
}
if(LB_ERR==m_lbxUsers.SetItemData(iNewIndex,(DWORD)pUser))
{
AfxMessageBox("setitemdata returned LB_ERR. this will probably cause serious problems if you attempt to update or delete this item from the listbox");
}
}



UpdateData(false);


}
else
{
pUser->m_strUserID = strPrevUserID;
pUser->m_strUserName = strPrevUserName;
pUser->m_iStatus = iPrevStatus;
AfxMessageBox("SaveUser failed");
}



}
}
else
{
AfxMessageBox("you must first select a user id to save");
}



}



BOOL CUserMaintenanceDlg::SaveUser(User *pUser)
{
BOOL bSuccess = false;
CDatabase db;

try
{
if(db.Open("Is"))
{
CString strSQL = CString("UPDATE student SET ");
strSQL += CString("sUserName = '") + pUser->m_strUserName+CString("',");
strSQL += CString("iStatus='");
char szStatus[10];
itoa(pUser->m_iStatus,szStatus,10);
strSQL += szStatus;
strSQL += "'";
strSQL += CString("where sUserID=");
strSQL += CString("'")+pUser->m_strUserID+CString("'");
db.ExecuteSQL(strSQL);
bSuccess=true;
}

}
catch(CDBException *pe)
{
AfxMessageBox(pe->m_strError);
if(db.IsOpen())
{
db.Close();
}
pe->Delete();
}
return bSuccess;
}
...全文
26 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧