delphi中ado如何动态连接数据库 Delphi / Windows SDK/API http://www.delphi2007.net/DelphiDB/html/delphi_20061218205039233.html
delphi中ado如何动态连接数据库?
var s: String; begin s := PromptDataSource(Handle, ADOConnection1.ConnectionString); if CompareText(s, ADOConnection1.ConnectionString) <> 0 then ADOConnection1.ConnectionString := s; end;
var s: String; begin s := PromptDataSource(Handle, ADOConnection1.ConnectionString); if CompareText(s, ADOConnection1.ConnectionString) <> 0 then begin ADOConnection1.Connected := False; ADOConnection1.ConnectionString := s; ADOConnection1.Connected := True; end; end;
如果处于连接状态,ConnectionString比较是不准确的,还是应该先断开连接,修改如下: var s: String; begin ADOConnection1.Connected := False; s := PromptDataSource(Handle, ADOConnection1.ConnectionString); if CompareText(s, ADOConnection1.ConnectionString) <> 0 then ADOConnection1.ConnectionString := s; ADOConnection1.Connected := True; end;
直接传个ADOConnection对象不就完了?如果在多个窗口像这样写那要生成多少个连接?
|
请发表评论