首页上一页 1 下一页尾页 1 条记录 1/1页
■■关于模糊查询
发表在C语言图书答疑
2011-03-09
是否精华
是
否
版块置顶:
是
否
Visual C++从入门到精通 刘锐宁 宋坤编著 P420页检索按钮的单击事件如下:
void CSearchesDlg::OnButsearch()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString strField;
m_Combo.GetLBText(m_Combo.GetCurSel(),strField);
if(strField.IsEmpty() || m_Text.IsEmpty())
{
MessageBox("检索信息不能为空!");
return;
}
ADO m_Ado;
m_Ado.OnInitADOConn();
CString sql = "select * from employees";
m_Ado.m_pRecordset = m_Ado.OpenRecordset(sql);
CString str;
str.Format("%s = '%s'",strField,m_Text);
m_Ado.m_pRecordset->Filter = (_bstr_t)str;
m_Ado.m_pRecordset->Requery(0);
m_Grid.DeleteAllItems();
int i = 0;
while(!m_Ado.m_pRecordset->adoEOF)
{
m_Grid.InsertItem(i,"");
m_Grid.SetItemText(i,0,(char*)(_bstr_t)m_Ado.m_pRecordset->GetCollect("编号"));
m_Grid.SetItemText(i,1,(char*)(_bstr_t)m_Ado.m_pRecordset->GetCollect("姓名"));
m_Grid.SetItemText(i,2,(char*)(_bstr_t)m_Ado.m_pRecordset->GetCollect("学历"));
m_Ado.m_pRecordset->MoveNext();//将记录集指针移动到下一条记录
i++;
}
m_Ado.CloseRecordset();
m_Ado.CloseConn();//断开数据库连接
}
如果想进行模糊查询,应该怎么弄?
void CSearchesDlg::OnButsearch()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString strField;
m_Combo.GetLBText(m_Combo.GetCurSel(),strField);
if(strField.IsEmpty() || m_Text.IsEmpty())
{
MessageBox("检索信息不能为空!");
return;
}
ADO m_Ado;
m_Ado.OnInitADOConn();
CString sql = "select * from employees";
m_Ado.m_pRecordset = m_Ado.OpenRecordset(sql);
CString str;
str.Format("%s = '%s'",strField,m_Text);
m_Ado.m_pRecordset->Filter = (_bstr_t)str;
m_Ado.m_pRecordset->Requery(0);
m_Grid.DeleteAllItems();
int i = 0;
while(!m_Ado.m_pRecordset->adoEOF)
{
m_Grid.InsertItem(i,"");
m_Grid.SetItemText(i,0,(char*)(_bstr_t)m_Ado.m_pRecordset->GetCollect("编号"));
m_Grid.SetItemText(i,1,(char*)(_bstr_t)m_Ado.m_pRecordset->GetCollect("姓名"));
m_Grid.SetItemText(i,2,(char*)(_bstr_t)m_Ado.m_pRecordset->GetCollect("学历"));
m_Ado.m_pRecordset->MoveNext();//将记录集指针移动到下一条记录
i++;
}
m_Ado.CloseRecordset();
m_Ado.CloseConn();//断开数据库连接
}
如果想进行模糊查询,应该怎么弄?