try                 //查询当前时间的数据记录是否已存在
  SQLSent:='Select ID from pharosdata where phaCode ='''+Code+''''+'and Type='+IntToStr(J)+' and time='''+ HAPPEN_TIME +'''';
  ADOConnection1.Close;
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add(SQLSent);  ADOQuery1.Open;
  
  QuyRsl:=ADOQuery1.RecordCount;  
except
end;数据库里明明有这条记录,但是查询返回QuyRs1=0,大概,是什么原因?

解决方案 »

  1.   

    你这样写当然查不到~
    try
      ADOConnection1.Close; 
      ADOQuery1.Close; 
      ADOQuery1.SQL.Clear; 
      SQLSent:='Select ID from pharosdata where phaCode ='''+Code+''''+'and Type='+IntToStr(J)+' and time='''+ HAPPEN_TIME +''''; 
       ADOQuery1.SQL.Add(SQLSent);
     ADOQuery1.Open; 
    QuyRsl:=ADOQuery1.RecordCount;  
    except 
    end; 
      

  2.   

    try                //查询当前时间的数据记录是否已存在 
      SQLSent:='Select ID from pharosdata where phaCode ='''+Code+''''+'and Type='+IntToStr(J)+' and time='''+ HAPPEN_TIME +''''; 
      ADOConnection1.Close; 
      ADOQuery1.Close; 
      ADOQuery1.SQL.Clear; 
      ADOQuery1.SQL.Add(SQLSent);   ADOQuery1.Open; 
      
      QuyRsl:=ADOQuery1.RecordCount;  
    except 
    end; 数据库里明明有这条记录,但是查询返回QuyRs1=0,大概,是什么原因?>>>>>>>>>>>要先连接数据库,检查一下连接是否正确。
      

  3.   

    设断点,把SQL取出来了,在数据库中执行一下看看是哪写的不对
      

  4.   

    ADOConnection1.Close; 
    为什么要close?
      

  5.   

    我上面的错了,不好意思,不小心看花眼了。
    按楼上的建议把ADOConnection1.Close; 去掉试验一下  
      

  6.   

    1、谢谢  zxf_feng 的方法,问题找到了..
    自己写的第一步循环把记录改掉了,囧2、习惯了,这些写
    当ADOConnection1.Close; 
    ADOQuery.Open执行后,ADOConnection1,还是会自动Open.