ADO操作SQL Server2000数据库的问题

shiboily 2009-04-25 04:01:23
strSQL1.Format("select srcIP,sum(flux) as totalFlux from (%s) as Temp group by srcIP" , strSQL);
strSQL是一个语句,之前已经能单独成功得到一个结果集,如:select * from Data,
可是执行strSQL1就是会抛出异常,操作失败,大家帮帮忙!
...全文
55 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shiboily 2009-04-25
  • 打赏
  • 举报
回复
是不是第二次查询前要把第一次的结果集关掉?我试试看
shiboily 2009-04-25
  • 打赏
  • 举报
回复
strSQL.Format("%s order by revTime",temp);
m_Ado.GetRecordSet(strSQL);
while(!m_Ado.m_pRecordset->adoEOF)
{
CString s0 = (char*)_bstr_t(m_Ado.m_pRecordset->GetCollect("protocol"));
CString s1 = (char*)_bstr_t(m_Ado.m_pRecordset->GetCollect("srcIP"));
CString s2 = (char*)_bstr_t(m_Ado.m_pRecordset->GetCollect("srcPort"));
CString s3 = (char*)_bstr_t(m_Ado.m_pRecordset->GetCollect("destIP"));
CString s4 = (char*)_bstr_t(m_Ado.m_pRecordset->GetCollect("destPort"));
CString s5 = (char*)_bstr_t(m_Ado.m_pRecordset->GetCollect("flux"));
CString s6 = (char*)_bstr_t(m_Ado.m_pRecordset->GetCollect("revTime"));
int index;
index = m_ListCtrl.InsertItem(0,s0);
m_ListCtrl.SetItem(index,1,LVIF_TEXT,s1, 0, 0, 0,0);
m_ListCtrl.SetItem(index,2,LVIF_TEXT,s2, 0, 0, 0,0);
m_ListCtrl.SetItem(index,3,LVIF_TEXT,s3, 0, 0, 0,0);
m_ListCtrl.SetItem(index,4,LVIF_TEXT,s4, 0, 0, 0,0);
m_ListCtrl.SetItem(index,5,LVIF_TEXT,s5, 0, 0, 0,0);
m_ListCtrl.SetItem(index,6,LVIF_TEXT,s6, 0, 0, 0,0);
m_Ado.m_pRecordset->MoveNext();
} 到这边程序都运行出来了,结果也对的
if(BST_CHECKED == IsDlgButtonChecked(IDC_CHECK7))
{
CString strSQL1;
strSQL1.Format("select srcIP,sum(flux) as totalFlux from (%s) as Temp group by srcIP" , strSQL);
m_Ado.GetRecordSet(strSQL1); 到这里提示执行Select语句失败
while(!m_Ado.m_pRecordset->adoEOF)
{
CString ip = (char*)_bstr_t(m_Ado.m_pRecordset->GetCollect("srcIP"));
CString total_flux = (char*)_bstr_t(m_Ado.m_pRecordset->GetCollect("totalFlux"));
int index;
index = m_SrcList.InsertItem(0,ip);
m_SrcList.SetItem(index,1,LVIF_TEXT,total_flux, 0, 0, 0,0);
m_Ado.m_pRecordset->MoveNext();
}
}
请大侠指教
zhaohongbo83 2009-04-25
  • 打赏
  • 举报
回复
你的记录集是不是没有关,然后第二次再查数据的时候又打开一次 报错了

你debug一下看看!

不行就把代码贴出来,帮你看看

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧