文章作者 100test 发表时间 2007:10:10 12:45:51
来源 100Test.Com百考试题网
ACCESS技巧集 cwxiao888(收藏)
1.DELPHI中*作ACCESS数据库(建立.mdb文件,压缩数据库)
以下代码在WIN2K,D6,MDAC2.6下测试通过,
编译好的程序在WIN98第二版无ACCESS环境下运行成功.
//在之前uses ComObj,ActiveX
//=============================================================================
// Procedure: GetTempPathFileName
// Author : ysai
// Date : 2003-01-27
// Arguments: (None)
// Result : string
//=============================================================================
function GetTempPathFileName():string.
//取得临时文件名
var
SPath,Sfile:array [0..254] of char.
begin
GetTempPath(254,SPath).
GetTempFileName(SPath, ~SM ,0,SFile).
result:=SFile.
DeleteFile(PChar(result)).
end.
//=============================================================================
// Procedure: CreateAccessFile
// Author : ysai
// Date : 2003-01-27
// Arguments: FileName:String.PassWord:string=
// Result : boolean
//=============================================================================
function CreateAccessFile(FileName:String.PassWord:string= ):boolean.
//建立Access文件,如果文件存在则失败
var
STempFileName:string.
vCatalog:OleVariant.
begin
STempFileName:=GetTempPathFileName.
try
vCatalog:=CreateOleObject( ADOX.Catalog ).
vCatalog.Create(format(SConnectionString,[STempFileName,PassWord])).
result:=CopyFile(PChar(STempFileName),PChar(FileName),True).
DeleteFile(STempFileName).
except
result:=false.
end.
end.
//=============================================================================
// Procedure: CompactDatabase
// Author : ysai
// Date : 2003-01-27
// Arguments: AFileName,APassWord:string
// Result : boolean
//=============================================================================
function CompactDatabase(AFileName,APassWord:string):boolean.
//压缩与修复数据库,覆盖源文件
var
STempFileName:string.
vJE:OleVariant.
begin
STempFileName:=GetTempPathFileName.
try
vJE:=CreateOleObject( JRO.JetEngine ).
vJE.CompactDatabase(format(SConnectionString,[AFileName,APassWord]),
format(SConnectionString,[STempFileName,APassWord])).
result:=CopyFile(PChar(STempFileName),PChar(AFileName),false).
DeleteFile(STempFileName).
except
result:=false.
end.
end.
//=============================================================================
// Procedure: ChangeDatabasePassword
// Author : ysai
// Date : 2003-01-27
// Arguments: AFileName,AOldPassWord,ANewPassWord:string
// Result : boolean
//=============================================================================
function ChangeDatabasePassword(AFileName,AOldPassWord,ANewPassWord:string):boolean.
//修改ACCESS数据库密码
var
STempFileName:string.
vJE:OleVariant.
begin
STempFileName:=GetTempPathFileName.
try
vJE:=CreateOleObject( JRO.JetEngine ).
vJE.CompactDatabase(format(SConnectionString,[AFileName,AOldPassWord]),
format(SConnectionString,[STempFileName,ANewPassWord])).
result:=CopyFile(PChar(STempFileName),PChar(AFileName),false).
DeleteFile(STempFileName).
except
result:=false.
end.
end.
相关文章
VB:使ACCE 数据库在网络使用中保持同步
如何给ODBC连接打开连接池
Delphi中使用ACCE 技巧集
Acce 无需D 文件快速连接SQLServer的方法!
操作系统环境Environ函数
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛