PDA

Ver la Versión Completa : No me recore el string Grind y me ingresa la misma linea


Edwardfeliz
24-02-2016, 04:42:01
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.

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:


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
Gracias ^\||/^\||/