工控编程吧
标题:
上位机MFC如何使用ADO在数据库中查找记录
[打印本页]
作者:
qq263946146
时间:
2019-8-9 12:26
标题:
上位机MFC如何使用ADO在数据库中查找记录
https://www.gkbc8.com/thread-15136-1-1.html
如下图。我们在上边帖子的代码基础上实现数据库查找功能。
(, 下载次数: 2)
上传
点击文件名下载附件
查找按钮的点击函数如下。
在数据库中查找指定的内容
工控编程吧。
void CGkbc8Dlg::OnButton4()
{
if (!(m_pRecordset->State & adStateOpen))
{
AfxMessageBox((_T("记录集未打开。")));
return;
}
//查找条件
CString strCriteria = _T("");
CString strName = _T("");
strCriteria.Format(_T("NAME like '%s'"), "工控编程吧");
//查找记录集
CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST);
pListCtrl->DeleteAllItems();
if (m_pRecordset->BOF && m_pRecordset->adoEOF)
{
return;
}
m_pRecordset->MoveFirst();
int n = 0;
m_pRecordset->Find(_bstr_t(strCriteria), 0, adSearchForward);
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->Find(_bstr_t(strCriteria), 1, adSearchForward);
}
}
复制代码
(, 下载次数: 0)
上传
点击文件名下载附件
[MFC408]1[/MFC408]
[weixinlianxi]1[/weixinlianxi]
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4