Показать сообщение отдельно
  #2  
Старый 07.07.2011, 01:28
lmikle lmikle вне форума
Модератор
 
Регистрация: 17.04.2008
Сообщения: 8,087
Версия Delphi: 7, XE3, 10.2
Репутация: 49089
По умолчанию

В ini-файле тебе надо хранить 2 connection string и можно так же сами запросы. Ну и просто читать их оттуда и перенастраивать ADOConnection и ADOQuery. Типа:

Код:
uses IniFiles;

function TForm1.GetCount(AConnectionString, AQuery : String) : Integer;
begin
  ADOQuery1.Active := False;
  ADOConnection1.Connected := False;

  Try  
    ADOConection.ConnectionString := AConnectionString;
    ADOConnection.Connected := True;
  
    ADOQuery.SQL.Clear;
    ADOQuery.SQL.Add(AQuery);
    ADOQuery.Open;
    Result := ADOQuery.Fields[0].AsInteger;
  Finally
    If ADOQuery.Active Then ADOQuery.Close;
    ADOConnection.Connected := False;
  End;  
end;

procedure TForm1.Button1Click(Sender : TObject);
var
  Ini : TIniFile;
  AConn, ASQL : String;
begin
  Ini := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
  
  AConn := Ini.ReadString('Connection1','ConnString','');
  ASQL := Ini.ReadString('Connection1','Query','');
  Cells[1,1] := GetCount(AConn,ASQL);

  AConn := Ini.ReadString('Connection2','ConnString','');
  ASQL := Ini.ReadString('Connection2','Query','');
  Cells[2,1] := GetCount(AConn,ASQL);

  Ini.Free;
end;  

Ну и соотв. ini-файл
Код:
[Connection1]
ConnString=Здесь первая ConnectionString
Query=select count(template_id) as f1 from os_eqm.devices where template_id <>0

[Connection2]
ConnString=Здесь вторая ConnectionString
Query=select count(def_monitoring_type)from devices_active where nvl(def_monitoring_type,0) <> 0
Ответить с цитированием