Hello.
When running I get the error.
Field ID not found.
Code: Select all
          Close;
          SQL.Clear;
          SQL.Add(
            'INSERT INTO ventas ( ENTIDAD, ALMACEN, USUARIO, CLIENTE, VENDEDOR, VENTAREF, TOTAL, IVA, CAMBIO, REDONDEO, FECHA, HORA)');
          SQL.Add('values (:ENTIDAD, :ALMACEN, :USUARIO, :CLIENTE,' +
              ':VENDEDOR ' + ',' + sVentaRef +
              ', :TOTAL, :IVA, :CAMBIO, :REDONDEO, :FECHA, :HORA);');
 [b]   Options.ReturnParams := True;
[/b]
[b]SQL.Add(' SET :ID = SCOPE_IDENTITY(); ');[/b]
 ExecSQL;
 ID:= FieldByName('ID').AsInteger;
 
When testing step check that this code is never executed.
Code: Select all
procedure TfrmVentas.UniQueri1BeforeUpdateExecute(Sender: TDataSet;
  StatementTypes: TStatementTypes; Params: TDAParams);
begin
  If stInsert IN StatementTypes then // otherwise there is no param with this name
    Params.ParamByName('CLAVE').ParamType := ptInputOutput;
end;
 
Thanks.