用delphi怎么创建一个access数据库

luzhongjia1 2004-05-08 11:26:39
用delphi怎么创建一个access数据库DB,并在创建后用ADOConnection连接,完毕用
ADOQuery建立table1和table2表.
...全文
140 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
飞天揽月 2004-07-06
自己看一下

1.DELPHI中操作ACCESS数据库(建立.mdb文件,压缩数据库)
以下代码在WIN2K,D6,MDAC2.6下测试通过,
编译好的程序在WIN98第二版无ACCESS环境下运行成功.
//在之前uses ComObj,ActiveX
//声明连接字符串
Const
SConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;'
+'Jet OLEDB:Database Password=%s;';

//=============================================================================
// 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;
  • 打赏
  • 举报
回复
飞天揽月 2004-07-06
程序创建access数据库

111111111建库:
//创建ACCESS2000数据库
function CreateAssess2000Database(const DatabaseName : string) : Boolean;
var
Cat:OleVariant;
begin
Cat:=CreateOleObject('ADOX.Catalog');
Cat.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + DatabaseName);
end;
  • 打赏
  • 举报
回复
飞天揽月 2004-07-06
ding
  • 打赏
  • 举报
回复
CoolApp 2004-07-05
同样需要
  • 打赏
  • 举报
回复
Frank.WU 2004-06-16
幫助頂出去:)
  • 打赏
  • 举报
回复
luzhongjia1 2004-05-08
是动态连接的,不是用ODBC连接.
也就是保存到动态的一个路径,并且要连接.
  • 打赏
  • 举报
回复
发帖
Delphi

5124

社区成员

Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
帖子事件
创建了帖子
2004-05-08 11:26
社区公告
暂无公告