https://www.gkbc8.com/thread-15135-1-1.html同样也是在前面一帖子基础上实现删除功能。
上位机MFC如何使用ADO在数据库中删除记录
- void CGkbc8Dlg::OnButton3()
- {
- if (!(m_pRecordset->State & adStateOpen))
- {
- AfxMessageBox((_T("记录集未打开。")));
- return;
- }
- //获得记录集当前位置
- CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST);
- POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
- if (pos == NULL)
- {
- return;
- }
- int nItem = pListCtrl->GetNextSelectedItem(pos);
-
- //删除记录集
- if (m_pRecordset->BOF && m_pRecordset->adoEOF)
- {
- return;
- }
- m_pRecordset->MoveFirst();
- m_pRecordset->Move((long)nItem);
- m_pRecordset->Delete(adAffectCurrent);
- m_pRecordset->Update();
- //读取记录集
- pListCtrl->DeleteAllItems();
- if (m_pRecordset->BOF && m_pRecordset->adoEOF)
- {
- return;
- }
- m_pRecordset->MoveFirst();
- int n = 0;
- while (!m_pRecordset->adoEOF)
- {
- _variant_t varValue;
- CString strName = _T("");
- int nAge = 0;
- varValue = m_pRecordset->GetCollect(_variant_t(_T("NAME")));
- if (varValue.vt != VT_NULL)
- {
- strName = varValue.bstrVal;
- }
- else
- {
- strName = _T("");
- }
- varValue = m_pRecordset->GetCollect(_variant_t(_T("AGE")));
- if (varValue.vt != VT_NULL)
- {
- nAge = varValue.intVal;
- }
- else
- {
- nAge = 0;
- }
- //刷新ListCtrl
- CString strText = _T("");
- strText.Format(_T("%d"), n + 1);
- pListCtrl->InsertItem(n, strText);
- strText.Format(_T("%s"), strName);
- pListCtrl->SetItemText(n, 1, strText);
- strText.Format(_T("%d"), nAge);
- pListCtrl->SetItemText(n, 2, strText);
- n++;
- m_pRecordset->MoveNext();
- }
- }
复制代码
上位机VC MFC程序开发精典实例大全源码与视频讲解配套下载408例 经历1年的编程与录制点击进入查看
如果您认可,可联系功能定制! 如果您着急,充值会员可直接联系发您资料!
|