Delphi中实现Access数据库备份和恢复的代码

2016-08-22 10:23:23来源:http://jxyx521.blog.51cto.com/7643111/1289334作者:jyxy521人点击


http://guohongjian81.blog.163.com/blog/static/34535941201262924347173/

常用的是delphi备份SQL Server,较少用delphi备份Access的,今天有人问了一下,顺便把代码贴出来。有人可能会有需要。(使用的是文件复制和替换方式)

procedure TBackup.Button1Click(Sender: TObject);varpath:string;beginif SaveDialog1.Execute thenif SaveDialog1.FileName <> '' thenbeginpath := ExtractFilePath(application.ExeName);trycopyfile(pchar(path+ 'db.mdb'), pchar(SaveDialog1.FileName+'.bak'), false); showmessage('备份成功!');exceptshowmessage('备份失败,请重试!');end;end;end;

//恢复数据库procedure TBackup.Button3Click(Sender: TObject);varpath:string;beginif OpenDialog1.Execute thenif OpenDialog1.FileName <> '' thenbeginpath := ExtractFilePath(application.ExeName);try

TBackup.ADOConnection1.Connected := false;Deletefile(path+'db.mdb');copyfile(pchar(OpenDialog1.FileName),pchar(path + 'db.mdb'), false);showmessage('成功恢复数据!');Application.Terminate;exceptshowmessage('恢复失败,请重试!');end;end;end;


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台