我以前的程序中用到的,只要你的DB数据库跟应用程序在一起就可以直接使用.不过,我以前
用的是MDB数据库,你要改成DB的,我用ADO连接,你建一个DataMould,在其Create事件中加入
下列代码,再Connect就行了.
function GetCurPath:string;
var
szFileName:array[0..49] of char;
szModuleName:array[0..19] of char;
iSize:integer;
begin
StrPCopy(szModuleName,'NameOfModule');
iSize:=GetModuleFileName(GetModuleHandle(szModuleName),szFileName,SizeOf(szFileName));
if iSize>0 then
Result:=string(szFileName)
else
Result:='';
end;
procedure TDMData.DataModuleCreate(Sender: TObject);
begin
AdoConn.Connected:=False;
GetCurPath;
AdoConn.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=admin;Data Source=';
AdoConn.ConnectionString:=AdoConn.ConnectionString+GetFileName(StrPath,'company.mdb')+';';//我这儿是MDB,你改成你的DB,然后根据ADO的连接改掉Connectionstring,
AdoConn.ConnectionString:=AdoConn.ConnectionString+'Mode=Share Deny None;Extended Properties="";Locale Identifier=1028;Jet OLEDB:System database="";';
AdoConn.ConnectionString:=AdoConn.ConnectionString+'Jet OLEDB:Registry Path="";Jet OLEDB
atabase Password="";Jet OLEDB:Engine Type=5;Jet OLEDB
atabase Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;';
AdoConn.ConnectionString:=AdoConn.ConnectionString+'Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;';
AdoConn.ConnectionString:=AdoConn.ConnectionString+'Jet OLEDB
on''t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;';
AdoConn.Connected:=True;
end;