怎樣用程序為控制access里的修復及壓縮功能﹐謝謝(20分)

  • 主题发起人 主题发起人 lzl200188
  • 开始时间 开始时间
L

lzl200188

Unregistered / Unconfirmed
GUEST, unregistred user!
怎樣用程序為控制access里的修復及壓縮功能﹐謝謝
 
function daocompactdb:boolean; &nbsp; &nbsp; &nbsp; &nbsp; //compactdatabase<br>&nbsp; var<br>&nbsp; &nbsp; srcfile,dstfile:widestring;<br>&nbsp; &nbsp; db:_DBEngine;<br>&nbsp; &nbsp; dtbs:database;<br>&nbsp; begin<br>&nbsp; &nbsp;srcfile:=extractfilepath(application.ExeName)+'agritax.mdb';<br>&nbsp; &nbsp;dstfile:=extractfilepath(application.ExeName)+'tempfile.mdb';<br><br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp; &nbsp;db:=coDBEngine.Create;<br>&nbsp; &nbsp; &nbsp; &nbsp;dtbs:=db.OpenDatabase(srcfile,true,false,';pwd=agriculture');<br>&nbsp; &nbsp; &nbsp; &nbsp;dtbs.NewPassword('agriculture','');<br>&nbsp; &nbsp; &nbsp; &nbsp;dtbs.Close;<br>&nbsp; &nbsp; &nbsp; &nbsp;dtmd.DataModule1.adocntion.Connected:=false;<br>&nbsp; &nbsp; &nbsp; &nbsp;db.CompactDatabase(srcfile,dstfile,emptyparam,emptyparam,'');<br>&nbsp; // &nbsp; &nbsp; db.CompactDatabase(srcfile,dstfile,emptyparam,emptyparam,'agriculture');<br>&nbsp; &nbsp; &nbsp; &nbsp;dtmd.DataModule1.adocntion.Connected:=false;<br><br>&nbsp; &nbsp; &nbsp; &nbsp;if not copyfile(pchar(dstfile),pchar(srcfile),false) then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deletefile(dstfile);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result:=false;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br><br>&nbsp; &nbsp; &nbsp;finally<br>&nbsp; &nbsp; &nbsp; &nbsp;dtbs:=db.OpenDatabase(srcfile,true,false,';pwd=');<br>&nbsp; &nbsp; &nbsp; &nbsp;dtbs.NewPassword('','agriculture');<br>&nbsp; &nbsp; &nbsp; &nbsp;dtbs.Close;<br>&nbsp; &nbsp; &nbsp; &nbsp;dtmd.DataModule1.adocntion.Connected:=true;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;//dtmd.DataModule1.adocntion.Connected:=true;<br>&nbsp; &nbsp; &nbsp;result:=true;<br>&nbsp; &nbsp;except // wrap up<br>&nbsp; &nbsp; &nbsp;dtmd.DataModule1.adocntion.Connected:=true;<br>&nbsp; &nbsp; &nbsp;result:=false;<br>&nbsp; &nbsp; &nbsp;dtmd.DataModule1.adocntion.Connected:=true;<br>&nbsp; &nbsp;end; &nbsp; &nbsp;// try/except<br>&nbsp; &nbsp;deletefile(dstfile);<br>&nbsp; &nbsp;dtmd.DataModule1.adocntion.Connected:=true;<br><br>&nbsp;end;<br>&nbsp;function daorepairdb:boolean; &nbsp; &nbsp; &nbsp; //repairdatabase<br>&nbsp;var<br>&nbsp; &nbsp;db:_DBEngine;<br>&nbsp;begin<br>&nbsp; &nbsp;db:=coDBEngine.Create;<br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp;db.RepairDatabase(extractfilepath(application.ExeName)+'agritax.mdb');<br>&nbsp; &nbsp; &nbsp;result:=true;<br>&nbsp; &nbsp;except<br><br>&nbsp; &nbsp; &nbsp;result:=false;<br>&nbsp; &nbsp;end;<br>&nbsp;end;<br><br>function getusername(userid :string):string;<br>begin<br>&nbsp; with DataModule1.adoqry do<br>&nbsp; begin<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; Active := False;<br>&nbsp; &nbsp; except<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; SQL.Add('select username from sysusers where userid='''+userid+'''');<br>&nbsp; &nbsp; Active := True;<br>&nbsp; &nbsp; if not (BOF and EOF) then<br>&nbsp; &nbsp; &nbsp; Result:=FieldByName('username').asstring<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; Result := '';<br><br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; Active := False;<br>&nbsp; &nbsp; except<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>
 

Similar threads

后退
顶部