Error in DBExpress with Delphi + SQLSERVER

1

Dear, I have this error:

  SQL STATE 42000, SQL Error CODE 201

Look for information on the internet and I can not find the solution. Client side script:

 var client : TTServerMethodsClient;
    var ds:TDataset;
    var dst:TDataset;
    var ch : char;
    var canti : String;
    var eproceso : String;
    var suma : Double;
    var multi:Double;
    var resultado : Double;

    begin
         client :=   TTServerMethodsClient.Create(SQLConnectionDTComprobantes.DBXConnection);
         ds := DBGridDTCompo.DataSource.DataSet;

         if not SQLConnectionDTComprobantes.Connected  then
                SQLConnectionDTComprobantes.Connected := True;



        fecha := ds.FieldByName('fecha').Value;
        numerocompo := ds.FieldByName('numero_comprobante').Value;
        codigo_producto := ds.FieldByName('codigo_producto').Value;
        valor_unitario := ds.FieldByName('valor_unitario').Value;
        canti :=  ds.FieldByName('cantidad').Value;
        eproceso :=  '1';

        try

  //INSERT        label2.Caption:=client.ProcedureSDTComprobantes(strToFloat(canti),codigo_producto,strToDateTime(fecha),numerocompo,strToFloat(valor_unitario),strToInt(eproceso));

        finally
         FreeAndNil(client);
        end;

    end;

SQLSERVER procedure:

GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE  [dbo].[setComprobantes]
@numero_comprobante varchar(12),
@fecha datetime,
@codigo_producto varchar(10),
@cantidad decimal(15, 4),
@valor_unitario decimal(15, 4),
@eproceso int
as
BEGIN
    DECLARE 
        @variable INT



    SET @variable = (SELECT eproceso FROM detalle_comprobante WHERE eproceso = @eproceso);

    IF @variable=NULL

    INSERT INTO detalle_comprobante (numero_comprobante,fecha,cantidad, codigo_producto,valor_unitario,eproceso) 
    VALUES 
    (@numero_comprobante,@fecha,@cantidad,@codigo_producto,@valor_unitario,@eproceso);

    ELSE
        UPDATE detalle_comprobante
        SET 
            fecha = @fecha,
            codigo_producto =@codigo_producto, 
            cantidad =@cantidad, 
            valor_unitario =@valor_unitario,
            eproceso = @eproceso
            WHERE numero_comprobante=@numero_comprobante

END

Server-Side Script:

function TTServerMethods.ProcedureSDTComprobantes(canti: Double; coditemsd: string; fechas : TDateTime; numcompro:String;  valorUnis:Double;const eproceso : Integer): String;
begin
 try
       if not EjemploDatasnap.Connected then
          EjemploDatasnap.Connected := true;


       if SQLStoredDTComprobantes.Active then
          SQLStoredDTComprobantes.Active := False;


       //SQLStoredDTComprobantes.Open;
       SQLStoredDTComprobantes.ParamByName('cantidad').AsString := floatToStr(canti);
       SQLStoredDTComprobantes.ParamByName('coditems').AsString := coditemsd;
       SQLStoredDTComprobantes.ParamByName('fecha').AsString := DateTimeToStr(fechas);
       SQLStoredDTComprobantes.ParamByName('numero_comprobante').AsString := numero_comprobante;
       SQLStoredDTComprobantes.ParamByName('valoruni').AsString := floatTostr(valorUnis);
       SQLStoredDTComprobantes.ParamByName('eproceso').AsString := intToStr(eproceso);
       //SQLStoredDTComprobantes.Close;

       SQLStoredDTComprobantes.Active := True;
       //SQLDataSetIProductos.Active:=False;



   except on
   E: Exception do
    Result := E.Message;
end;

end;

The error is when I run the procedure, I think the parameters or something is causing me a connection error, but I do not realize where that error is.

    
asked by Nahuel Jakobson 18.05.2018 в 16:50
source

2 answers

1

The error seems to be that the stored procedure is waiting for a parameter that is not reaching it.

In line SQLStoredDTComprobantes.ParamByName('numero_comprobante').AsString := numero_comprobante; you are not assigning the value that arrives in the method, it should be SQLStoredDTComprobantes.ParamByName('numero_comprobante').AsString := numcompro;

So the server-side method would look like this:

function TTServerMethods.ProcedureSDTComprobantes(canti: Double; coditemsd: string; fechas : TDateTime; numcompro:String;  valorUnis:Double;const eproceso : Integer): String;
   begin
   try
       if not EjemploDatasnap.Connected then
          EjemploDatasnap.Connected := true;

       if SQLStoredDTComprobantes.Active then
          SQLStoredDTComprobantes.Active := False;


       //SQLStoredDTComprobantes.Open;
       SQLStoredDTComprobantes.ParamByName('cantidad').AsString := floatToStr(canti);
       SQLStoredDTComprobantes.ParamByName('coditems').AsString := coditemsd;
       SQLStoredDTComprobantes.ParamByName('fecha').AsString := DateTimeToStr(fechas);
       SQLStoredDTComprobantes.ParamByName('numero_comprobante').AsString := numcompro;
       SQLStoredDTComprobantes.ParamByName('valoruni').AsString := floatTostr(valorUnis);
       SQLStoredDTComprobantes.ParamByName('eproceso').AsString := intToStr(eproceso);
       //SQLStoredDTComprobantes.Close;

       SQLStoredDTComprobantes.Active := True;
       //SQLDataSetIProductos.Active:=False;

    except on
    E: Exception do
    Result := E.Message;
    end;

end;
    
answered by 22.05.2018 в 16:23
0

The error was in the procedure storing SQLServer and in TTServerMtehods .

I was calling parameters that I was not considering in both things. That is, it called parameters from SqlServer that had not taken them into account in the method developed in delphi.

    
answered by 24.05.2018 в 14:45