我用BDE连的数据库,现在想做备份数据操作,请问delphi中代码怎么写?

解决方案 »

  1.   

    ACCESS就只有一个单一的.mdb文件.
    不像SQL数据库一样.
    因此只要用到简单的复制文件就可以了.
      

  2.   

    var
      MyFileName:string;
    begin
      MyFileName:= '';
      try
          SaveDialog1.DefaultExt:='.mdb';
          SaveDialog1.Filter:= '数据库文件|*.mdb|所有文件|*.*';
        if SaveDialog1.Execute then
        begin
          MyFileName := SaveDialog1.FileName;
          if MyFileName <> '' then
          begin
            if CopyFile(Pchar(ExtractFilePath(Application.ExeName)+'计费系统.mdb'), Pchar(MyFileName), false) then
            begin
              Application.MessageBox('数据备份成功','提示',Mb_ok + mb_iconinformation);
            end;
          end;
        end;
      except
        Application.MessageBox('数据备份失败','提示',Mb_ok + mb_iconError);
      end;
    end;
      

  3.   

    var
      MyFileName,aa:string;
    begin
      MyFileName:='';
      try
          openDialog1.DefaultExt:='.mdb';
          openDialog1.Filter:= '数据库文件|*.mdb|所有文件|*.*';
        if OpenDialog1.Execute then
        begin
          MyFileName:=OpenDialog1.FileName;
          if MyFileName <> '' then
          begin
            aa:=ExtractFilePath(Application.ExeName) +'计费系统.mdb';
            if CopyFile(Pchar(MyFileName),Pchar(aa), false) then
            begin
              DM.ADOConnection1.Close;
              DM.ADOConnection1.Open;
              Application.MessageBox('数据恢复成功,请您重起系统','提示',Mb_ok + mb_iconinformation);
            end;
          end;
        end;
      except
        Application.MessageBox('数据恢复失败','提示',Mb_ok + mb_iconError);
      end;
    end;