各位兄弟在Delphi中怎样连接一个动态的数据库,然后怎样调用这个数据库。谢谢!

来源:百度知道 编辑:UC知道 时间:2024/06/03 18:39:25

const
MDBCONNECTIONSTR = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%S;Persist Security Info=False';
MYSQLCONNECTIONSTR = 'DRIVER={MySQL ODBC 5.1 Driver}; SERVER=%s; PORT=%s; DATABASE=%s; USER=%s; PASSWORD=%s; OPTION=3;';

implementation
{$R *.dfm}

procedure Tmain.btnLocalClick(Sender: TObject);
var
fPath:string;
begin
with TOpenDialog.Create(nil) do
begin
Filter:='Access数据库|*.mdb|all files|*.*';
if Execute() then
fPath:=FileName;
Free;
end;
qryMDB.Close;
qryMDB.ConnectionString:=format(MDBCONNECTIONSTR,[fPath]);
//
qryMDB.SQL.Clear;
qryMDB.SQL.Add('select * from content');
try
qryMDB.Open;
except
ShowMessage('获取本地数据库失败了');
end;
end;

procedure Tmain.btnRemoteClick(Sender: TObject);
begin
qryMySQL.ConnectionString:=Format(MYSQL