var
abc:string;
procedure TForm1.Button1Click(Sender: TObject);
begin   adotable2.First;
   while not adotable2.Eof do
   begin
      abc:=adotable1.Fields[0].Value;
      adoquery1.Active:=false;
      adoquery1.SQL.Clear;
      adoquery1.SQL.Add('select * from away where name=abc');
      adoquery1.Active:=true;
     if adoquery1.Eof=true
     then
        begin
        adotable2.Edit;
        adotable2.Delete;
        end;   end;end;

解决方案 »

  1.   

    提示是缺少常数。在if adoquery1.eof=true那句。
      

  2.   

    你的程序很乱。
       while not adotable2.Eof do
       begin
          abc:=adotable1.Fields[0].Value; //adotable1打开了没有?FIelds[0].Value是否可能为NULL? 使用abc:=VarToStr(adotable1.Fields[0].Value);
          adoquery1.Active:=false;
          adoquery1.SQL.Clear;
          adoquery1.SQL.Add('select * from away where name=abc');
          adoquery1.Active:=true;
         if adoquery1.Eof=true
         then
            begin
            adotable2.Edit; //如果要删除的话,不需要这一句
            adotable2.Delete;
            end;
        //如果不删除,则应该用ADOTable2.Next指向下一个记录,否则会死循环。
       end;
      

  3.   

    提示是缺少参数。在if  adoquery1.eof=true那句。
      

  4.   

    if adoquery1.eof=true这一句没有错误。
    不过还是建议采用if adoquery1.eof then ...
    不要与true或者false进行比较。
      

  5.   

    非常感谢windindance(风舞轻扬)的回复,我刚刚试了一下好像还是相同的错误。
      

  6.   

    FIelds[0].Value是打开的,
    但是FIelds[0].Value可能为NULL,
    风舞轻扬大哥还在吗?
      

  7.   

    adoquery1.SQL.Add('select * from away where name=abc');-->错了 
    adoquery1.SQL.Add('select * from away where name=''abc''');
      

  8.   

    楼上的少了一个'
    adoquery1.SQL.Add('select * from away where name=abc');--->错了改成adoquery1.SQL.Add('select * from away where name='''abc'''');
      

  9.   

    to:jinjazz错误还是依然存在,'参数不足,期待是1'可能是SQL语句或者是我的ACCESS数据库的问题,但问题不知道出在哪里?
      

  10.   

    我没看到你的abc是变量,不好意思
    adoquery1.SQL.Add('select * from away where name='''+abc+'''');
      

  11.   

    你的abc是什么类型的变量?如果不是string的用参数传就可以了
      

  12.   

    adoquery1.SQL.Add('select * from away where name=' ''+abc+'''');
      

  13.   

    jinjazz说对,我改了sql语句adoquery1.SQL.Add('select * from away where name=''abc''');后可以正常执行程序了,但是运行的结果不是我想要的。adotable2和adoquery1中分别存有一张表,我是想要在adotable2中挑出所有name字段和adoquery中name字段相同的数据,把所有在adoquery1中找不到的都删除掉,但是这段程序run的结果很不对,大家再看看好吗?
      

  14.   

    我没看到你的abc是变量,不好意思
    adoquery1.SQL.Add('select * from away where name='''+abc+'''');--------------这一贴你看了没阿,老大
      

  15.   

    delete from table2 where name not in
    (select name from table1)
    干吗要一个一个找出来啊
      

  16.   

    begin
       adoquery1.Active:=false;
       adoquery1.SQL.Clear;
       adoquery1.SQL.Add('delete from adotable2 where name not in (select name from adotable1)');
       adoquery1.Active:=true;
    end;
    运行上面的代码DELPHI说找不到adotable2,我已经添加了一个adotable了啊,而且active也是true,怎么会这样呢?
      

  17.   

    有些地方要改正哦
    1。习惯上不要用adoquery1.active:=false OR true 这个一般是作为判断用的
       IF NOT adoquery1.active then adoquery1.open
    2。你写的SQL也不对要用参数应该这样写:
      with adoquery1 do
      begin
          close;
          sql.clear;
          sql.add('select * from away where name='''+abc+'''');
          open;
      end;
    3。对于一个数据集不要同时又是Edit状态又要Delete
    var
    abc:string;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
       if not adotable2.eof then adotable2.First;//要判断一下
       while not adotable2.Eof do
       begin
          if adotable1.Fields[0].Value=NULL then  //确保没有空值
             abc:=''
          else
             abc:=adotable1.Fields[0].Value; 
          adoquery1.close;
          adoquery1.SQL.Clear;
          adoquery1.SQL.Add('select * from away where name='''+abc+'''');
          adoquery1.open;
          if adoquery1.Eof then adotable2.Delete;
          adotable2.next;  //你的结构很乱我不知道你在这里用循环的目的要加上这句避免   死循环
       end;end;
      

  18.   

    var
    abc:string;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
       adotable1.open;
       adotable2.First;
       while not adotable2.Eof do
       begin
          abc:=adotable1.Fields[0].Value;
          adoquery1.Active:=false;
          adoquery1.SQL.Clear;
          adoquery1.SQL.Add('select * from away where name='''abc'''');
          adoquery1.Active:=true;
          adoquery1.first;
         if adoquery1.Eof=true
         then
            begin
            adotable2.Edit;
            adotable2.Delete;
            adoquery1.next;
            end;
          adotable2.close;
       end;end;
      

  19.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      adoquery1.close;
      adoquery1 .SQL.text := 'delete from table1 where name not in (select distinct name from table2)';
      adoquery1 .ExecSQL;
    end;