Void CUserInfoDlg: : OnBnClickedSave ()
{
Int nCount=m_list. GetItemCount ();
Cstrings sNumb, sName, sSex, sAge, sDept, sLevel, sPhone, sEmail, sFlag, sID.
Cstrings sSql;
for(int i=0; I
SNumb=m_list. GetItemText (I, 0).
SName=m_list. GetItemText (I, 1);
SSex=m_list. GetItemText (I, 2);
SAge=m_list. GetItemText (I, 3);
SDept=m_list. GetItemText (I, 4);
SLevel=m_list. GetItemText (I, 5);
SPhone=m_list. GetItemText (I, 6);
SEmail=m_list. GetItemText (I, 7);
SFlag=m_list. GetItemText (I, 8).
SID=m_list. GetItemText (I, 9);
If (sFlag=="N")//new user
{
SSql. Format (" Insert into the UserInfo (Code, UserName, \
Sex, Age, Branch, RightLevel, Phone, EMail) \
Values (' % s', '% s',' % s', % d, '% s', % d,' % s', '% s'). "
SNumb, sName sSex, atoi (sAge), sDept, atoi (sLevel), sPhone, sEmail);
AfxMessageBox (sSql);
Try
{
TheApp. M_pConn - & gt; Execute (_bstr_t (sSql), NULL, adCmdText);
}
The catch (_com_error & amp; E)
{
AfxMessageBox (e.D escription ());
}
}
Else if (sFlag=="M")//Modify user
{
AfxMessageBox (sID);
SSql. Format (" Update the UserInfo Set Code='% s', the UserName=' % s', \
='% s' Sex, the Age=% d, Branch=' % s', RightLevel=% d, \
='% s' Phone, EMail=' % s' where id=% d ", \
SNumb, sName sSex, atoi (sAge), sDept, atoi (sLevel), sPhone, sEmail, atoi (sID));
AfxMessageBox (sSql);
Try
{
TheApp. M_pConn - & gt; Execute (_bstr_t (sSql), NULL, adCmdText);
}
The catch (_com_error & amp; E)
{
AfxMessageBox (e.D escription ());
}
}
}
}
CodePudding user response:
I find the method of the Internet, I can't, the followingElse if (sFlag=="D")
{
Try
{
SSql. The Format (_T (" DELETE from the UserInfo where id=% d "));
_variant_t RecordsAffected;
TheApp. M_pConn - & gt; Execute (_bstr_t (sSql), & amp; RecordsAffected adCmdText);
AfxMessageBox (_T (" deleted successful!" ));
}
Catch _com_error * (e)
{
AfxMessageBox (e - & gt; ErrorMessage ());
}
& RecordsAffected this parameter should be a representative to delete rows, not too understand this parameter
CodePudding user response:
Use a SQL statement to delete the database corresponding to the yao, wrong just look at your SQL statement is correctCodePudding user response: