m_pZoneSet.CreateInstance(__uuidof(Recordset));
try
{
m_pZoneSet->Open( "SELECT * FROM table_3" ,            
   theApp.m_pConnection.GetInterfacePtr(),  
   adOpenDynamic,
   adLockOptimistic,
   adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
       
try
{
while(!m_pZoneSet->adoEOF)
{
     var=m_pZoneSet->GetCollect("zonenum");
     if(var.vt!=VT_NULL)
strnum=(LPCSTR)_bstr_t(var); //strnum将是下一步的查询条件之一
     var=m_pZoneSet->GetCollect("zonename");
     if(var.vt!=VT_NULL)
strname=(LPCSTR)_bstr_t(var);
                    
m_pSet.CreateInstance(__uuidof(Recordset));
                
strsql.Format("SELECT * FROM table_2 WHERE zone=%s AND day=%d AND month=%d AND year=%d",zonenum,day_day,day_month,day_year);//将上一步得到的strnum作为条件之一,执行出错,把这个条件去掉就没问题了,问题就出在这上面,可是我觉得没问题啊,那位帮忙看一下
 _bstr_t sql=strsql;
try
{
m_pSet->Open(  sql,          
       theApp.m_pConnection.GetInterfacePtr(),  
       adOpenDynamic,
       adLockOptimistic,
       adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
。。m_pZoneSet->MoveNext();//是第一个记录集
}//while
}//try
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}

解决方案 »

  1.   

    strsql.Format("SELECT * FROM table_2 WHERE zone=%s AND day=%d AND month=%d AND year=%d",zonenum,day_day,day_month,day_year);//将上一步得到的strnum作为条件之一,执行出错,把这个条件去掉就没问题了,问题就出在这上面,可是我觉得没问题啊,那位帮忙看一下
    ---------------有个地方打错了,zonenum应为上面的strnum,但程序中并没有打错。
      

  2.   

    strsql.Format("SELECT * FROM table_2 WHERE zone='%s' AND day=%d AND month=%d AND year=%d",zonenum,day_day,day_month,day_year);
    //%s的两端应该加单引号。
    实际上简单的方法是将SQL语句直接在数据库中执行,可以快速的找到错误。
      

  3.   

    查一下zonenum 的内容,还有 %s 应加单引号的