void CMyATLOLEDBDlg::OnButtonDel()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
POSITION pos;
int iPos;
CString strPersonID;
pos = m_listLinkInfo.GetFirstSelectedItemPosition();
if (pos == NULL)
{
::MessageBox(NULL, "请选择要删除的记录!", "通信录", MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
return;
}
if(AfxMessageBox("真的要删除该记录吗?", MB_ICONQUESTION | MB_YESNO|MB_DEFBUTTON2) == IDNO)
return;
iPos = m_listLinkInfo.GetNextSelectedItem(pos);
strPersonID = m_listLinkInfo.GetItemText(iPos, 5);
CLinkInfo linkInfo;
strcpy (linkInfo.m_strFilter, "PersonID = ");
strcat(linkInfo.m_strFilter, strPersonID);
HRESULT hr = linkInfo.Open();
if (FAILED(hr))
{
::MessageBox(NULL, "打开数据库联系人表失败!", "数据库操作", MB_OK|MB_ICONEXCLAMATION);
return;
}
hr = linkInfo.m_session.StartTransaction(); //Make Changes permanent
linkInfo.MoveFirst();
linkInfo.Delete();
hr = linkInfo.m_session.Commit(); //Make Changes permanent
linkInfo.Close();
ShowItem("");
UpdateData(FALSE);
}