有关动态创建数据库及连接数据库?(200分)

K

kchsun

Unregistered / Unconfirmed
GUEST, unregistred user!
要动态创建Access数据库,并动态连接,要求只使用delphi 4.0自带数据库
控件,我看过以前的问题,不太明白,最好讲细点,如:
1.要创建'd:/data/database.mdb'应该怎么做,需要哪几个控件,
作什么设置。
2.现要动态连接'd:/data/database.mdb',需要哪几个控件,作什么设置
 
Some limitations of the Access files under BDE

1) You can't easily create new *.MDB database files. You will
normally create an empty .MDB file in Access 97, then you can
create tables in it from Delphi.

2) Their are sometimes "wierd datatypes" in Access tables that are
hard to deal with in Delphi.

3) All *.MDB tables carry a lot of extra baggage with them. There
are forms stored in them, and all kinds of other objects. You can
only manipulate a small portion of the stuff that can be found
inside a typical *.MDB file!

4) Delphi's BDE can not correctly use all the data integrity features
of the .MDB format. Some of your record changes from Delphi can
cause unexpected results.

5) For these reasons, I recommend against using *.MDB tables as
your primary tables in a Delphi program. I think you should only
support *.MDB for import/export purposes. Go with Paradox tables
as your native format, unless you have a back-end DBMS.
//引自del_db.txt
 
请参看
<a href="http://202.120.85.61/delphibbs/DispQ.asp?LID=131755">这里:</a>
 
你还是先建mdb吧,手工建不知用oleserver行不行。
 
还有:<a href="http://202.120.85.61/delphibbs/DispQ.asp?LID=129540">这里</a>;)

看了一下老问题,好象已经能解答你的问题了。
 
oleserver太麻烦, 还要装access, 还是用diamond的构件, 支持创建access.
不过注意access的驱动必须安装先: 最简单用mdac_typ.exe安装, 包括许多驱动.
 
to amo:你说的我之前已经看过了,跟我的要求不一样,我是要动态键库,不是表。
至于动态连接,说的也不明白。
to cytown:我没用过diamond,大概介绍一下
 
diamond可以从http://cytown.yeah.net上找到:)
 
还是我给你做个实例吧。
以下过程要用到D5的access97单元或d4的access_tlb.


var AccessApplication:_Application;
AliasParams: TStringList;
begin
//打开access oleserver
AccessApplication:=CoApplication.Create;
//创建新mdb !
AccessApplication.NewCurrentDatabase('d:/data/database.mdb');
AccessApplication.Quit(0);
//添加新alias
AliasParams := TStringList.Create;
try
AliasParams.Add('DATABASE NAME=d:/data/database.mdb');
SESSION.ConfigMode:=cmSession;
Session.AddAlias('MyNewAlias', 'MSACCESS', AliasParams);
Session.ConfigMode:=cmAll;
finally
AliasParams.Free;
end;
//下面是对该mdb的操作
with Query1 do begin
Close;
DatabaseName:='mynewalias';
SQL.Add('create table aaa(id char(10))');
ExecSQL;
Close;
SQL.Clear;
SQL.Add('select * from aaa');
Open;
end;
end;
 
to menxin:我的D4里没有access_tlb单元,说文件找不到,是我装少了吗?
 
to cytown:
我已经下了diamond,不知道它那四个控件是不是与delphi自带的完全兼容,也就
是说我能不能直接拿它替代我原来的控件,而不用改程序,另,动态创建我没研究
出来,主要是没时间。谢了!
 
2.现要动态连接'd:/data/database.mdb',需要哪几个控件,作什么设置
答:
仅用Tdatesource及Ttable即可.
设置:Datesource连接Table1.
Table1的DatabaseName:='d:/data';
TableName:=database.mdb;
 
100% compatible!
 
如何动态创建,怎么没人帮答一下?:-?
 
delphi 4必须用project->import type library 导入access8的tlb(必须装有
access97)!建议直接用d5吧。
 
看来这个问题也就这样了。多谢各位!
 
多人接受答案了。
 
你还没创建出来?
 
to menxin:我改用文件拷贝了。没时间研究。多谢关心!
 
顶部