void CMyADODlg::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("select * from LinkInfo");
	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;
	}


	_ConnectionPtr	m_pConnection;//创建连接对象指针
	m_pConnection.CreateInstance(__uuidof(Connection));//创建连接对象实例

	try                 
	{	
		// 打开本地Access库AddressBook.mdb
		m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\AddressBook.mdb","","",adModeUnknown);
	}
	catch(_com_error e)
	{
		AfxMessageBox("数据库连接失败,确认数据库AddressBook.mdb是否在当前路径下!");
		return;
	}  

	_variant_t m_pRecordset;
	CString strTmp;
	strTmp.Format("update LinkInfo set Address='%s', Email='%s', Name='%s', Phone='%s', Postcode='%s' where PersonID=%s",
			m_strAddress, m_strEmail, m_strName, m_strPhone, m_strPostcode, m_strPersonID);//构造sql语句

	try
	{
		m_pConnection->CursorLocation = adUseClient;
		m_pConnection->Execute(_bstr_t(strTmp), &m_pRecordset, adExecuteNoRecords);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
		return;	
	}


	if(m_pConnection->State)		
		m_pConnection->Close();//关闭连接对象
	m_pConnection= NULL;  

	CDialog::OnOK();

}