我想比较数据表中的记录,程序如下:
var a,b,c,d:boolean;
begin
with adoquery1 do
begin
 first;
    a:=fields[2].Value;
    b:=fields[3].Value;
    c:=fields[4].Value;
    d:=fields[5].Value;
     next;
     while not eof do
      begin
      if(fields[2].Value=a)and(fields[3].Value=b)and(fields[4].Value=c)and(fields[5].Value<>d)
        then showmessage('找到记录')
        else next;
       end;
       end;
运行时,表中存在我要找的记录,却没有信息提示(showmessage).只是指针指向最后一条记录。请问问题在哪儿

解决方案 »

  1.   

    var a,b,c,d:boolean;
    begin
    with adoquery1 do
    begin
     first;
        a:=fields[2].Value;
        b:=fields[3].Value;
        c:=fields[4].Value;
        d:=fields[5].Value;
         next;
         while not eof do
          begin
             if(fields[2].Value=a)and(fields[3].Value=b)and(fields[4].Value=c)and(fields[5].Value<>d)
          then 
          begin
            showmessage('找到记录');
          end
          else next;
          end;
    end;
      

  2.   

    then后只有一条语句,也要加begin ..end吗?
      

  3.   

    少了一个end了吧。其它好像没有什么错误啊。
      

  4.   

    从你这段代码看,你是寻找于第一条记录相似的(fields[2].Value=a)and(fields[3].Value=b)and(fields[4].Value=c)and(fields[5].Value<>d)记录,是这样么?看起来没什么错误,只是不知道你的field有没有特别的类型,例如浮点数之类的,可能用“=”不能精确判断,需要模糊判断
      

  5.   

    是要在表中找和第二条记录想同的记录么?
    还是比第一条?
    如果比第一条的话,while前面那个next去掉