For a:=StrToInt(Edit3.Text) to StrToInt(Edit4.Text) do
    begin
    For c:=StrToInt(Edit1.Text) to StrToInt(Edit6.Text) do
    begin
    with adoquery1 do
    begin
      close;
      sql.Clear;
      sql.Add('insert into Tba_kwsz (cs,bm) values (:b,:c)');
      parameters.ParamByName('b').Value :=edit6.Text;
      parameters.ParamByName('c').Value :=a+c;
 adoquery1.ExecSQL;
如果这次插入的数据a+c在数据库中存在就跳过,如果不存在就插入

解决方案 »

  1.   

       For c:=StrToInt(Edit1.Text) to StrToInt(Edit6.Text) do 
       begin 
         with adoquery2 do 
         begin 
           close; 
           sql.Clear; 
           sql.Add(select * from Tba_kwsz where bm=:c'); 
           parameters.ParamByName('c').Value :=a+c; 
           open;
         end;
         if recordCount>0 then continue     with adoquery1 do 
         begin 
           close; 
           sql.Clear; 
           sql.Add('insert into Tba_kwsz (cs,bm) values (:b,:c)'); 
           parameters.ParamByName('b').Value :=edit6.Text; 
           parameters.ParamByName('c').Value :=a+c; 
           adoquery1.ExecSQL; 
        end;
      end;
       
      

  2.   

    1楼的好象有点问题 只有一个ADOQuery,并且是For里套了一个For  For a:=StrToInt(Edit3.Text) to StrToInt(Edit4.Text) do 
        begin 
        For c:=StrToInt(Edit1.Text) to StrToInt(Edit6.Text) do 
        begin 
        with adoquery1 do 
        begin 
          close;
          sql.Clear; 
          sql.Add(select * from Tba_kwsz where bm=:c'); 
          parameters.ParamByName('c').Value :=a+c; 
          open; 
          if RecordCount>0 then continue ;      close; 
          sql.Clear; 
          sql.Add('insert into Tba_kwsz (cs,bm) values (:b,:c)'); 
          parameters.ParamByName('b').Value :=edit6.Text; 
          parameters.ParamByName('c').Value :=a+c; 
          adoquery1.ExecSQL; 
        End;
    End;
      

  3.   

    不好意思上面的代码少了一个End; 
     For a:=StrToInt(Edit3.Text) to StrToInt(Edit4.Text) do 
        begin 
        For c:=StrToInt(Edit1.Text) to StrToInt(Edit6.Text) do 
        begin 
        with adoquery1 do 
        begin 
          close;
          sql.Clear; 
          sql.Add(select * from Tba_kwsz where bm=:c'); 
          parameters.ParamByName('c').Value :=a+c; 
          open; 
          if RecordCount>0 then continue ;      close; 
          sql.Clear; 
          sql.Add('insert into Tba_kwsz (cs,bm) values (:b,:c)'); 
          parameters.ParamByName('b').Value :=edit6.Text; 
          parameters.ParamByName('c').Value :=a+c; 
          adoquery1.ExecSQL; 
        End;
    End;
    End;
      

  4.   

    上面的也行.  我一般用的是WHILE NOT ADOQUERY1.EOF do //先用select 查出你要修改的内容
      begin
        ADOQUERY1.edit;
        ADOQUERY1.fieldbyname('ID').asdtring:=edit1.Text;
        ADOQUERY1.fieldbyname('ID2').asdtring:=edit2.Text;
        //........
        ADOQUERY1.post;
        ADOQUERY1.next;
      end;