Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > SQL
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #4  
Antiguo 25-08-2013
nefore nefore is offline
Miembro
NULL
 
Registrado: jun 2013
Posts: 25
Poder: 0
nefore Va por buen camino
Cita:
Empezado por nefore Ver Mensaje
Hola muchas gracias por tomarte tu tiempo para responder a mi problema. Podrias ponerme un ejemplo en codigo?, no tengo ni idea como manejar los componentes que me sugieres
Me respondo a mi mismo con un codigo de ejemplo que encontre:

Código:
procedure TForm2.FormCreate(Sender: TObject);
const
  { Connection string }
  ConnString =
  'Provider=SQLOLEDB.1;Persist Security Info=False;' +
  'User ID=%s;Password=%s;Data Source=%s;Use Procedure for Prepare=1;' +
  'Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;'+
  'Tag with column collation when possible=False';
 
  { SQL Query }
  SQLStr = 'SELECT * FROM customer WHERE customer_id = :AnId;';
 
  { User access }
  UserName = 'db_user_name';
  PassWord = 'db_pass_word';
  Server = 'my.db.server';
 
var
  ADOConn  : TADOConnection;
  ADOQuery : TADOQuery;
  DataSrc  : TDataSource;
  Param    : TParameter;
 
begin
  { Create an ADO connection. }
  ADOConn := TADOConnection.Create(Self);
  { Set up the provider engine }
 
  { Set up the connection string. }
  ADOConn.ConnectionString := Format(ConnString,
    [UserName, PassWord, Server]);
 
  { Disable login prompt. }
  ADOConn.LoginPrompt := False;
 
  try
    ADOConn.Connected := True;
  except
    on e: EADOError do
    begin
      MessageDlg('Error while connecting', mtError,
                  [mbOK], 0);
 
      Exit;
    end;
  end;
 
  { Create the query. }
  ADOQuery := TADOQuery.Create(Self);
  ADOQuery.Connection := ADOConn;
  ADOQuery.SQL.Add(SQLStr);
 
  { Update the parameter that was parsed from the SQL query: AnId. }
  Param := ADOQuery.Parameters.ParamByName('AnId');
  Param.DataType := ftInteger;
  Param.Value := 1;
 
  { Set the query to Prepared--it will improve performance. }
  ADOQuery.Prepared := true;
 
  try
    ADOQuery.Active := True;
  except
    on e: EADOError do
    begin
      MessageDlg('Error while doing query', mtError,
                  [mbOK], 0);
 
      Exit;
    end;
  end;
 
  { Create the data source. }
  DataSrc := TDataSource.Create(Self);
  DataSrc.DataSet := ADOQuery;
  DataSrc.Enabled := true;
 
  { Finally, initialize the grid. }
  DBGrid1.DataSource := DataSrc;
end;
Muchas gracias Galahad por tu tiempo para orientarme hacia donde buscar
Saludos!
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Unknown database. Alias.... Beaker_ Conexión con bases de datos 2 27-03-2012 20:44:44
Consulta con alias zvf SQL 0 27-02-2008 18:36:10
Paradox - Alias - DataBase Minio Conexión con bases de datos 3 22-11-2007 20:38:58
alias database anubis Tablas planas 1 14-06-2007 12:01:45
Error Unknown Database judit25 Conexión con bases de datos 1 26-05-2006 03:00:22


La franja horaria es GMT +2. Ahora son las 13:47:25.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi