Ver Mensaje Individual
  #3  
Antiguo 07-02-2006
TriLoCBA TriLoCBA is offline
Miembro
 
Registrado: jun 2005
Posts: 28
Reputación: 0
TriLoCBA Va por buen camino
Thumbs up Muchas gracias !!!

Muchas gracias ContraVeneno... tu solución funciono perfecta !!!...

Copio el codigo completo :
Código Delphi [-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
procedure ActualizarDBGrid2(Sender: TObject; Field: TField); //Metodo para mostrar el Stock del producto seleccionado en el DBGrid1
public
{ Public declarations }
end;
var
Form1: TForm1;
conSQL: TADOConnection;
cadenaSQL: String;
sp1:TADOStoredProc;
sp2:TADOStoredProc;
ds1:TDataSource;
ds2:TDataSource;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
//Conexion al Servidor SQL...
cadenaSQL:='Provider=SQLOLEDB.1;Password=MiPass;Persist Security Info=True;'+
'User ID=MiUsuario;Initial Catalog=MiBase;Data Source=10.0.0.1;'+
'Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;'+
'Workstation ID=MiEstacion;Use Encryption for Data=False;'+
'Tag with column collation when possible=False';
conSQL:=TADOConnection.Create(self);
conSQL.ConnectionString:= cadenaSQL;
conSQL.LoginPrompt:=False;
conSQL.Connected:= True;
//Completa el listado de productos en DBGrid1...
with sp1 do begin
sp1:=TADOStoredProc.Create(self);
Connection:= conSQL;
ProcedureName:= 'spListaProductos';
Parameters.Refresh;
Active:= true;
end;
ds1:=TDataSource.Create(self);
ds1.DataSet:= sp1;
DBGrid1.DataSource:=ds1;
ds1.OnDataChange:= ActualizarDBGrid2;
end;
procedure TForm1.ActualizarDBGrid2(Sender: TObject; Field: TField);
begin
//Muestra detalles de un producto especifico...
with sp2 do begin
sp2:= TADOStoredProc.Create(self);
Connection:= conSQL;
ProcedureName:= 'spStockProducto';
Parameters.Refresh;
Parameters.ParamByName('@Producto').Value:= ds1.DataSet.FieldByName('Producto').AsString;
Active:= true;
end;
ds2:=TDataSource.Create(self);
ds2.DataSet:= sp2;
DBGrid2.DataSource:= ds2;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ActualizarDBGrid2(nil,nil);
end;
end.


PD: Disculpa la cantidad de codigo, pero como soy un novato en esto, tener toda la codificacion a la hora de ejecutar un ejemplo siempre me ayuda mucho !!!
Responder Con Cita