ADO:修改

来源:互联网 发布:fs2you mac版本 编辑:程序博客网 时间:2024/05/06 06:13
void CMyADODlg::OnButtonModify() {// TODO: Add your control notification handler code hereCDlgModify dlg;POSITIONpos;intiPos;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 hereUpdateData(TRUE);if(m_strName.IsEmpty()){::MessageBox(NULL, "姓名不能为空!", "添加联系人", MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);return;}_ConnectionPtrm_pConnection;//创建连接对象指针m_pConnection.CreateInstance(__uuidof(Connection));//创建连接对象实例try                 {// 打开本地Access库AddressBook.mdbm_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();}

原创粉丝点击