procedure TForm1.EmptyDbf(const AName: string);
var
  s : string;
begin
  s := 'delete from '+ AName ;
  with Query1 do
  begin
    if Active then Active := False;
    SQL.Clear;
    SQL.Add(s);
    query1.Prepared:=true;
    ExecSQL;
  end;
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  EmptyDbf(dsDbfName.FieldByName('DBFNAME').AsString);
  ShowMessage('OK');
end;procedure TForm1.BitBtn3Click(Sender: TObject);
begin
  with dsDbfName do
    begin
     dsdbfname.First;
    while not Eof do
    begin
      EmptyDbf(FieldByName('DBFNAME').AsString);
      dsdbfname.Next;
    end;
  end;
  ShowMessage('All Ok');
end;end.
提示如下:
project1.exe raised exception class EDatabaseError with message'SQLConnection property'
required for this operation',process stopped.use step or run to continue.

解决方案 »

  1.   

    查看一下你形成的sql语句对不对
      

  2.   

    你的sql语句没有用对
    应该是delete from 表名 where 字段=AName
    问题在s := 'delete from '+ AName ;
      

  3.   

    procedure TForm1.EmptyDbf(const AName: string);
    var
      s : string;
    begin
      s := 'delete from '+ AName ;
      with Query1 do
      begin
        if Active then Active := False;
        SQL.Clear;
        SQL.Add(s);
    showmessage(query1.sql.text);//delete from table1 是对的啊我用的是对的啊
        query1.Prepared:=true;
        ExecSQL;
      end;
    end;procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
      EmptyDbf(dsDbfName.FieldByName('DBFNAME').AsString);
      ShowMessage('OK');
    end;procedure TForm1.BitBtn3Click(Sender: TObject);
    begin
      with dsDbfName do
        begin
         dsdbfname.First;
        while not Eof do
        begin
          EmptyDbf(FieldByName('DBFNAME').AsString);
          dsdbfname.Next;//运行到这里也出错
        end;
      end;
      ShowMessage('All Ok');
    end;end.
    提示如下:
    project1.exe raised exception class EDatabaseError with message'SQLConnection property'
    required for this operation',process stopped.use step or run to continue.
      

  4.   

    好了谢谢各位昏没把query的SQLconnection写上去昏