void CFileQuery::OnQuery()
{
// TODO: Add your control notification handler code here
m_ctlList.DeleteAllItems();
_RecordsetPtr m_pRecordset;
CString strSQL;
HRESULT hr;
//init query string
strSQL="select * from simplelist";
UpdateData(TRUE);
if(!m_strFileName.IsEmpty())
{
strSQL+=" where softBasic_Name like '"+m_strFileName+"%'";
}
try
{
hr=m_pRecordset.CreateInstance(__uuidof(Recordset));
if(SUCCEEDED(hr))
{
hr=m_pRecordset->Open(_variant_t(strSQL),(IDispatch*)theApp.m_pConnect,adOpenDynamic,adLockOptimistic,adCmdText);
}
TRACE("count=%d",m_pRecordset->GetRecordCount());
int iCount=m_pRecordset->GetRecordCount();
if(m_pRecordset->GetRecordCount()>0)
{
m_pRecordset->MoveFirst();
}
else
{
AfxMessageBox("没有记录!");
m_pRecordset->Close();
m_pRecordset=NULL;
m_strFileName="";
UpdateData(FALSE);
return;
}
int nItem=0;
while(!m_pRecordset->adoEOF)
{
nItem=m_ctlList.InsertItem(0xffff,_bstr_t(m_pRecordset->GetCollect("softbasic_id")));
for(int i=1;i<m_pRecordset->Fields->Count;i++)
m_ctlList.SetItem(nItem,i,1,_bstr_t(m_pRecordset->Fields->GetItem(_variant_t((long)i))->Value),NULL,0,0,0);
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
m_pRecordset->Close();
m_pRecordset=NULL;
return;
}
想作成根据文件名来进行查询,可是第一次生成的记录集为空,则以后都为空?为什么?好象生成的记录集没有被刷新!
{
// TODO: Add your control notification handler code here
m_ctlList.DeleteAllItems();
_RecordsetPtr m_pRecordset;
CString strSQL;
HRESULT hr;
//init query string
strSQL="select * from simplelist";
UpdateData(TRUE);
if(!m_strFileName.IsEmpty())
{
strSQL+=" where softBasic_Name like '"+m_strFileName+"%'";
}
try
{
hr=m_pRecordset.CreateInstance(__uuidof(Recordset));
if(SUCCEEDED(hr))
{
hr=m_pRecordset->Open(_variant_t(strSQL),(IDispatch*)theApp.m_pConnect,adOpenDynamic,adLockOptimistic,adCmdText);
}
TRACE("count=%d",m_pRecordset->GetRecordCount());
int iCount=m_pRecordset->GetRecordCount();
if(m_pRecordset->GetRecordCount()>0)
{
m_pRecordset->MoveFirst();
}
else
{
AfxMessageBox("没有记录!");
m_pRecordset->Close();
m_pRecordset=NULL;
m_strFileName="";
UpdateData(FALSE);
return;
}
int nItem=0;
while(!m_pRecordset->adoEOF)
{
nItem=m_ctlList.InsertItem(0xffff,_bstr_t(m_pRecordset->GetCollect("softbasic_id")));
for(int i=1;i<m_pRecordset->Fields->Count;i++)
m_ctlList.SetItem(nItem,i,1,_bstr_t(m_pRecordset->Fields->GetItem(_variant_t((long)i))->Value),NULL,0,0,0);
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
m_pRecordset->Close();
m_pRecordset=NULL;
return;
}
想作成根据文件名来进行查询,可是第一次生成的记录集为空,则以后都为空?为什么?好象生成的记录集没有被刷新!
解决方案 »
- webbrowse控件在edit模式下如何修改默认行间距和字体,解决了分不是问题
- 紧急求救如何根据现场掌声呼声高低进行打分
- 找工作中……每天散100分(今天散200分,等找到工作再多散分,以后就不再每天发了)
- 单文档视图在默认的view显示之前如何在Frame中获取该view的地址
- socket图片传输
- 基于对话框的mfc,如何把一个字符串显示到子对话框的控件中
- ★★★★#include问题,先来先得分!!★★★★
- 对PROCESSENTRY32结构的疑惑
- 如何给自己的程序产生的文件分配定做的图标?
- 如何指定MessageBox弹出框的按钮的语言属性,例如不让它显示“是”字,而是显示yes
- 界面版没能得到正确回答,很着急啊
- _ConnectionPtr无法声明为全局变量。
>>int iCount=m_pRecordset->GetRecordCount();使用GetRecordCount()返回记录总数时,必须先遍历记录集,你缺少这个步骤,导致GetRecordCount()返回的数据不正确。