Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   No me recore el string Grind y me ingresa la misma linea (https://www.clubdelphi.com/foros/showthread.php?t=89884)

Edwardfeliz 24-02-2016 04:42:01

No me recore el string Grind y me ingresa la misma linea
 
Saludos,
No me recore el string Grind y me ingresa la misma linea las mismas veces que el la cantidad de lineas.
Este es el codigo.
Código Delphi [-]
var
i : integer;
Begin
For i := 1 to Sg.RowCount-1 do
begin
QTemp.SQL.Clear;
QTemp.SQL.Text := 'Insert Into FacturaItem (CodFactura, CodParte, Cantidad, Descripcion, Precio,'+
                  'Total, Impuesto) Values '+
                  '(:CodFactura, :CodParte, :Cantidad, : Descripcion, :Precio, :Total, :Impuesto)';
QTemp.Parameters.ParamByName('CodFactura').Value   := CodigoFact;
QTemp.Parameters.ParamByName('CodParte').Value     := SG.Cells[0, SG.Row];
QTemp.Parameters.ParamByName('Cantidad').Value     := SG.Cells[1, SG.Row];
QTemp.Parameters.ParamByName('Descripcion').Value  := SG.Cells[2, SG.Row]; 
QTemp.Parameters.ParamByName('Precio').Value       := SG.Cells[3, SG.Row]; 
QTemp.Parameters.ParamByName('Total').Value        := SG.Cells[4, SG.Row]; 
QTemp.Parameters.ParamByName('Impuesto').Value     := SG.Cells[5, SG.Row];
QTemp.ExecSQL;
end;

Quiero que me agregue cada linea del string grid a la tabla de forma independiente.
Chao ^\||/

roman 24-02-2016 05:08:12

Bueno, eso sucede porque en el cuerpo del FOR, en lugar de usar la variable I usas SG.Row que nunca cambia. Por otro lado, no es necesario inicializar QTemp cada vez:

Código Delphi [-]
var
  i : integer;
begin
  QTemp.SQL.Clear;
  QTemp.SQL.Text := 'Insert Into FacturaItem (CodFactura, CodParte, Cantidad, Descripcion, Precio,'+
    'Total, Impuesto) Values '+
    '(:CodFactura, :CodParte, :Cantidad, : Descripcion, :Precio, :Total, :Impuesto)';

  for i := 1 to Sg.RowCount-1 do
  begin
    QTemp.Parameters.ParamByName('CodFactura').Value   := CodigoFact;
    QTemp.Parameters.ParamByName('CodParte').Value     := SG.Cells[0, i];
    QTemp.Parameters.ParamByName('Cantidad').Value     := SG.Cells[1, i];
    QTemp.Parameters.ParamByName('Descripcion').Value  := SG.Cells[2, i]; 
    QTemp.Parameters.ParamByName('Precio').Value       := SG.Cells[3, i]; 
    QTemp.Parameters.ParamByName('Total').Value        := SG.Cells[4, i]; 
    QTemp.Parameters.ParamByName('Impuesto').Value     := SG.Cells[5, i];
    QTemp.ExecSQL;
end;

LineComment Saludos

Edwardfeliz 24-02-2016 15:48:58

:p
 
Gracias ^\||/^\||/


La franja horaria es GMT +2. Ahora son las 03:53:43.

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