void CMyATLOLEDBDlg::OnButtonModify()
{
// TODO: Add your control notification handler code here
CDlgModify dlg;
POSITION pos;
int iPos;
pos = m_listLinkInfo.GetFirstSelectedItemPosition();
if (pos == NULL)
{
AfxMessageBox("请选择要修改的记录!");
return;
}
iPos = m_listLinkInfo.GetNextSelectedItem(pos);
dlg.m_strName = m_listLinkInfo.GetItemText(iPos, 0);
dlg.m_strPhone = m_listLinkInfo.GetItemText(iPos, 1);
dlg.m_strEmail = m_listLinkInfo.GetItemText(iPos, 2);
dlg.m_strAddress = m_listLinkInfo.GetItemText(iPos, 3);
dlg.m_strPostcode = m_listLinkInfo.GetItemText(iPos, 4);
dlg.m_strPersonID = m_listLinkInfo.GetItemText(iPos, 5);
dlg.DoModal();
ShowItem("");
UpdateData(FALSE);
}
void CDlgModify::OnButtonOk()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_strName.IsEmpty())
{
::MessageBox(NULL, "姓名不能为空!", "添加联系人", MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
return;
}
CLinkInfo linkInfo;
strcpy (linkInfo.m_strFilter, "PersonID = ");
strcat(linkInfo.m_strFilter, m_strPersonID);
HRESULT hr = linkInfo.Open();
if (FAILED(hr))
{
::MessageBox(NULL, "打开数据库联系人表失败!", "数据库操作", MB_OK|MB_ICONEXCLAMATION);
return;
}
linkInfo.m_session.StartTransaction();
linkInfo.MoveFirst();
strcpy(linkInfo.m_Address, m_strAddress);
strcpy(linkInfo.m_Email, m_strEmail);
strcpy(linkInfo.m_Name, m_strName);
strcpy(linkInfo.m_Phone, m_strPhone);
strcpy(linkInfo.m_Postcode, m_strPostcode);
hr = linkInfo.SetData();
linkInfo.m_session.Commit();
linkInfo.Close();
UpdateData(FALSE);
CDialog::OnOK();
}
OLEDB修改
最新推荐文章于 2024-11-06 11:17:40 发布