用ADO访问数据库
Function Conn_Db(DBPATH:STRING):Boolean;
VAr
list : TStringlist;
i : integer;
Begin
if FileExists(DBPATH) then
begin
Conn:=TAdoConnection.Create(nil);
Conn.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'
+'Password="";'+
'User ID=Admin;'+
'Data Source='+DBPATH+';'; Conn.LoginPrompt:=false;
try
conn.connected:=true;
list:=Tstringlist.Create;
conn.GetTableNames(list,false);
for i:=0 to list.count-1 do
begin
if list.IndexOf('menu')<0 then
begin
result:=false;
showmessage('缺少menu数据表!');
exit;
end;
if list.IndexOf('menu_item')<0 then
begin
result:=false;
showmessage('缺少menu_item数据表!');
exit;
end;
if list.IndexOf('adjunct')<0 then
begin
result:=false;
showmessage('缺少adjunct数据表!');
exit;
end;
if list.IndexOf('file')<0 then
begin
result:=false;
showmessage('缺少file数据表!');
exit;
end;
end;
result:=true;
Except
result:= false;
end;
end
else
begin
showmessage('该目录文件不存在:'+dbpath);
result:= false;
end;end;
上面是连接的
CONN是TADOCONNECTION,而且是全局变量
传输一个ACCESS数据库所在的PATH就可以了
Function Conn_Db(DBPATH:STRING):Boolean;
VAr
list : TStringlist;
i : integer;
Begin
if FileExists(DBPATH) then
begin
Conn:=TAdoConnection.Create(nil);
Conn.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'
+'Password="";'+
'User ID=Admin;'+
'Data Source='+DBPATH+';'; Conn.LoginPrompt:=false;
try
conn.connected:=true;
list:=Tstringlist.Create;
conn.GetTableNames(list,false);
for i:=0 to list.count-1 do
begin
if list.IndexOf('menu')<0 then
begin
result:=false;
showmessage('缺少menu数据表!');
exit;
end;
if list.IndexOf('menu_item')<0 then
begin
result:=false;
showmessage('缺少menu_item数据表!');
exit;
end;
if list.IndexOf('adjunct')<0 then
begin
result:=false;
showmessage('缺少adjunct数据表!');
exit;
end;
if list.IndexOf('file')<0 then
begin
result:=false;
showmessage('缺少file数据表!');
exit;
end;
end;
result:=true;
Except
result:= false;
end;
end
else
begin
showmessage('该目录文件不存在:'+dbpath);
result:= false;
end;end;
上面是连接的
CONN是TADOCONNECTION,而且是全局变量
传输一个ACCESS数据库所在的PATH就可以了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货