void CMyADODlg::OnButtonAdd() 
{
	// TODO: Add your control notification handler code here
	CDlgAdd dlg;
	dlg.DoModal();
	ShowItem("select * from LinkInfo");	
}


void CDlgAdd::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;
	}  


	_RecordsetPtr	m_pRecordset;//创建记录集指针						
	m_pRecordset.CreateInstance(__uuidof(Recordset));//创建记录集对象

	try
	{
		m_pRecordset->Open("SELECT * FROM LinkInfo",              // 查询LinkInfo表中所有字段
			m_pConnection.GetInterfacePtr(),				// 获取库接库的IDispatch指针
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}  

	//添加新记录
	m_pRecordset->AddNew();
	m_pRecordset->PutCollect("Name",_variant_t(m_strName));
	m_pRecordset->PutCollect("Phone",_variant_t(m_strPhone));
	m_pRecordset->PutCollect("Email", _variant_t(m_strEmail));
	m_pRecordset->PutCollect("Address", _variant_t(m_strAddress));
	m_pRecordset->PutCollect("Postcode", _variant_t(m_strPostcode));
	m_pRecordset->Update();

	m_pRecordset->Close();//关闭记录集对象
	m_pRecordset = NULL;

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

	UpdateData(FALSE);
	CDialog::OnOK();
}