source:=TFileStream.Create('源库文件名',fmOpenRead );//支持路径、扩展名; try target:=TFileStream.Create(filename,fmOpenWrite or fmCreate); try if target.CopyFrom(source,source.Size)=source.Size then ShowMessage('成功备份到'+filename+'!!!'); finally target.Free; end; finally source.Free; end;
begin pgbar.Max:=100; pgbar.Min:=0; pgbar.Step:=20; adoconnection1.Close; if adoconnection1.Connected then begin application.MessageBox('数据库数据正在使用','系统提示') end else begin try adocommand1.CommandText:='use master'; pgbar.StepIt; adocommand1.Execute ; adocommand1.CommandText:='execute sp_helpdevice'; pgbar.StepIt; adocommand1.Execute ; pgbar.stepit; adocommand1.CommandText:='backup database docmanage to disk=''c:\ccc.bak'' with init'; pgbar.StepIt; adocommand1.Execute ; adocommand1.CommandText:='backup log docmanage to ccc'; pgbar.StepIt; adocommand1.Execute; try aDOConnection1.Connected:=true; except ShowMessage('无法连接指定的数据库!'); application.Terminate; end; form1.Hide; if messagedlg('数据库docmanage已成功备份到c:\ccc.bak!是否继续?',mtwarning,[mbok],0)=mrok then begin form1.close end; except on exception do if ADOConnection1.InTransaction then ADOConnection1.RollbackTrans end; end; end;
TMethod=Record
pp:string[1];//标识是存ys1+bh还是ys2+bh
xh:string[3];
bh:string[12];
fb:string[8];
mc:string[56];
dw:string[8];
q:string[13];
jj:string[13];
rg:string[13];
jx:string[13];
qs:string[8];
xs:string[8];
xsa:string[8];
xsb:string[8];
xsc:string[8];
hsgs:string[254];
hss:string[254];
end;
methodfiletype=file of TMethod;
var
methodfile:methodfiletype;
methodrec:TMethod;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if savedialog1.Execute then
filename1:=savedialog1.FileName
else
exit;
tabname1:='ys1'+bh;
assignfile(methodfile,filename1);
rewrite(methodfile);
with datamodule1.Query1 do
begin
close;
sql.Clear;
sql.Add('select * from '+tabname1+''); //
open;
first;
i:=0 ;
while not eof do
begin
methodrec.pp:='1';
methodrec.xh:=fieldbyname('xh').asstring;
methodrec.bh:=fieldbyname('bh').AsString;
methodrec.fb:=fieldbyname('fb').AsString;
methodrec.mc:=fieldbyname('mc').AsString;
methodrec.dw:=fieldbyname('dw').AsString;
methodrec.q:=floattostr(fieldbyname('q').AsFloat);
methodrec.jj:=floattostr(fieldbyname('jj').AsFloat);
methodrec.rg:=floattostr(fieldbyname('rg').AsFloat);
methodrec.jx:=floattostr(fieldbyname('jx').AsFloat);
methodrec.qs:=floattostr(fieldbyname('gs').AsFloat);
methodrec.xs:=floattostr(fieldbyname('xs').AsFloat);
methodrec.xsa:=floattostr(fieldbyname('xsa').AsFloat);
methodrec.xsb:=floattostr(fieldbyname('xsb').AsFloat);
methodrec.xsc:=floattostr(fieldbyname('xsc').AsFloat);
methodrec.hsgs:=fieldbyname('hsgs').AsString;
methodrec.hss:=fieldbyname('hss').AsString; seek(methodfile,i);
i:=i+1;
write(methodfile,methodrec);
next;
end;
end;
filename:string;//目标库文件名
source,target: TFileStream;
begin
source:=TFileStream.Create('源库文件名',fmOpenRead );//支持路径、扩展名;
try
target:=TFileStream.Create(filename,fmOpenWrite or fmCreate);
try
if target.CopyFrom(source,source.Size)=source.Size then
ShowMessage('成功备份到'+filename+'!!!');
finally
target.Free;
end;
finally
source.Free;
end;
pgbar.Max:=100;
pgbar.Min:=0;
pgbar.Step:=20;
adoconnection1.Close;
if adoconnection1.Connected then
begin
application.MessageBox('数据库数据正在使用','系统提示')
end
else
begin
try
adocommand1.CommandText:='use master';
pgbar.StepIt;
adocommand1.Execute ;
adocommand1.CommandText:='execute sp_helpdevice';
pgbar.StepIt;
adocommand1.Execute ;
pgbar.stepit;
adocommand1.CommandText:='backup database docmanage to disk=''c:\ccc.bak'' with init';
pgbar.StepIt;
adocommand1.Execute ;
adocommand1.CommandText:='backup log docmanage to ccc';
pgbar.StepIt;
adocommand1.Execute;
try
aDOConnection1.Connected:=true;
except
ShowMessage('无法连接指定的数据库!');
application.Terminate;
end;
form1.Hide;
if messagedlg('数据库docmanage已成功备份到c:\ccc.bak!是否继续?',mtwarning,[mbok],0)=mrok then
begin
form1.close
end;
except
on exception do
if ADOConnection1.InTransaction then
ADOConnection1.RollbackTrans
end;
end;
end;