![]() |
problema con el borrodo cuando inserto. ADO
Saludos a todos.
El codigo siguiente en ADO inserta registro en una orden de compra y cuando estoy modificando no borra lo existente lo inserta de nuevo. Si ponemos en comentario el trozo de inserta lo borra! Gracias por anticipado. Try If DBMODULO1.ADOConnection1.InTransaction Then DBMODULO1.ADOConnection1.RollbackTrans; DBMODULO1.ADOConnection1.BeginTrans; Buscar la orden si existe OrdenCompra.Close; OrdenCompra.SQL.Clear; OrdenCompra.sql.Add('SELECT * FROM OrdenCompra WHERE tipo = :tipo and NUMERO = :NUMERO '); OrdenCompra.parameters.ParamByname('tipo').value := '01'; OrdenCompra.parameters.ParamByname('numero').value := EditFactura.Text; OrdenCompra.Open; ctransa := 'SRYNNA'; ctransa := Editfactura.text; if not OrdenCompra.isempty Then Begin ctransa := ''; if MsgBox(Application.Title, 'Movimiento Existe, Desea Modificar?',MB_YESNO + MB_ICONSTOP) = mrNO then Exit; Como existe la orden borramos el detalle OrdenCompra.Close; OrdenCompra.SQL.Clear; OrdenCompra.SQL.Add('DELETE FROM ordenCompra WHERE NUMERO = :NUMERO and Tipo = :tipo '); OrdenCompra.Parameters.ParamByname('numero').value := EditFactura.text; OrdenCompra.Parameters.ParamByname('tipo').value := '01'; OrdenCompra.ExecSQL; end; x := 0; y := ctmp1.RecordCount; ctmp1.First; Insertar Registro update1.Close; update1.SQL.Clear; update1.SQL.Add('INSERT INTO OrdenCompra (numero, Fecha, Suplidor, Cliente, Producto, Descrip, Unidad, Cantidad, Costo, Monto, Monto1, Observa, Refe, tipo, nombre, dire, ciudad , Tele, empresa, '); update1.SQL.Add(' Descrip1, Descrip2, Descrip3, Enviado, Requerido )'); update1.SQL.Add(' VALUES (:numero, :Fecha, :Suplidor, :Cliente, :Producto, :Descrip, :Unidad, :Cantidad, :Costo, :Monto, :Monto1, :Observa, :Refe, :tipo, :nombre, :dire, :ciudad , :Tele, :Empresa, '); update1.SQL.Add(' :Descrip1, :Descrip2, :Descrip3, :Enviado, :Requerido )'); WHILE CTMP1.EOF = FALSE DO BEGIN update1.Parameters.Parambyname('numero').value := EditFactura.Text; update1.Parameters.Parambyname('fecha').value := EditFecha1.Date; update1.Parameters.Parambyname('suplidor').value := Editcliente.text; update1.Parameters.Parambyname('cliente').value := ''; update1.Parameters.Parambyname('producto').value := cTmp1['Producto']; update1.Parameters.Parambyname('descrip').value := cTmp1['descrip']; update1.Parameters.Parambyname('unidad').value := cTmp1['Unidad']; update1.Parameters.Parambyname('cantidad').value := ctmp1['Cantidad']; update1.Parameters.Parambyname('costo').value := ctmp1['Precio']; update1.Parameters.Parambyname('monto').value := ctmp1['monto']; update1.Parameters.Parambyname('monto1').value := Edittotal.value; update1.Parameters.Parambyname('observa').value := EditObserva1.Text; update1.Parameters.Parambyname('refe').value := ''; update1.Parameters.Parambyname('tipo').value := '01'; update1.Parameters.Parambyname('nombre').value := memo1.lines[0]; update1.Parameters.Parambyname('dire').value := memo1.lines[1]; update1.Parameters.Parambyname('ciudad').value := memo1.lines[2]; update1.Parameters.Parambyname('tele').value := memo1.lines[3]; update1.Parameters.Parambyname('empresa').value := dbmodulo1.cntempresa; update1.Parameters.Parambyname('descrip1').value := copy(trim(ctmp1['Descrip1']),1,254); update1.Parameters.Parambyname('descrip2').value := copy(trim(ctmp1['Descrip1']),255,254); update1.Parameters.Parambyname('descrip3').value := copy(trim(ctmp1['Descrip1']),509,254); update1.Parameters.Parambyname('enviado').value := Enviado.text; update1.Parameters.Parambyname('requerido').value := Requerido.text; update1.ExecSQL; ctmp1.Next; end; If ctransa <> '' then Begin dbmodulo1.dbempresa.edit; dbmodulo1.dbempresa['Secuen10'] := dbmodulo1.dbempresa['Secuen10'] + 1; dbmodulo1.dbempresa.Post; end; DBMODULO1.dbempresa.UpdateBatch; DBMODULO1.ADOConnection1.CommitTrans; except // update1.CancelUpdates; DBMODULO1.dbEmpresa.CancelUpdates; DBMODULO1.ADOConnection1.RollbackTrans; exit; raise; {raise the exception to prevent a call to CommitUpdates!} End; |
La franja horaria es GMT +2. Ahora son las 09:27:10. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi