Ver Mensaje Individual
  #6  
Antiguo 03-05-2012
Avatar de olbeup
olbeup olbeup is offline
Miembro
 
Registrado: jul 2005
Ubicación: Santiago de la Ribera (España)
Posts: 688
Reputación: 21
olbeup Va camino a la fama
Te puedes crear un función que te devuelva todas las bases de datos:
Código Delphi [-]
// Devuelve todas las bases de datos
function TForm1.GetAllSysMSSDataBasesToStringsList: TStrings;
var
  adoCnnTmp: TADOConnection;
  ConnectionString: WideString;
begin
  ConnectionString := 'Provider=SQLNCLI.1;' +
                      'Password=123;' +
                      'Persist Security Info=True;' +
                      'User ID=sa;' +
                      'Data Source=SERVIDOR\SQLEXPRESS';

  adoCnnTmp := TADOConnection.Create(nil);
    adoCnnTmp.Connected := False;
    adoCnnTmp.LoginPrompt := False;
    adoCnnTmp.ConnectionString := ConnectionString;

  with TADOQuery.Create(nil) do
  begin
    Connection := adoCnnTmp;

    SQL.Add('SELECT');
    SQL.Add('    UPPER(name) AS DBNAME');
    SQL.Add('  FROM sys.databases');
    SQL.Add('  ORDER BY name');

    Open;

    Result := TStringList.Create;

    while (not Eof) do
    begin
      Result.Add(FieldByName('DBNAME').AsString);
      Next;
    end;

    adoCnnTmp.Free;
    Free;
  end;

end;

Después con un Button o en el OnCreate del formulario realizas:
Código Delphi [-]
...
begin
  ComboBox1.Items.Assign(GetAllSysMSSDataBasesToStringsList);
end;
y eso es todo.

Un saludo.
__________________
Al hacer una consulta SQL, haz que los demás te entiendan y disfruten de ella, será tú reflejo de tú saber.
Responder Con Cita