Search code examples
sql-serverdelphistored-proceduresado

Parameter of stored procedure not found


I use the following code to call my stored procedure using TADOStoredProc type

MySP.Connection := aConnection;
MySP.ProcedureName := 'dbo.UpdateErrors';
MySP.Parameters.ParamByName('@Error_Number').value := -1;
MySP.Parameters.ParamByName('@NewError_Name').value := 'errorM1';
MySP.Parameters.Refresh;

MySP.ExecProc;

The parameter @Error_Number is part of the stored procedure UpdateErrors using SQL Server Management Studio, I add snip image for confirmation

enter image description here

but I can't understand why I get an error


Solution

  • Simply use a TADOCommand

      MyCommand.Connection := aConnection;
      MyCommand.CommandText := 'EXEC dbo.UpdateErrors :Er, :Na'; //you can call the params what you want
      MyCommand.Parameters[0].value := -1; //Or you can do ParamByNname and use Er and Na (or whatever you called your params) instead of indices
      MyCommand.Parameters[1].value := 'errorM1';
      MyCommand.Execute;
    

    If you want to fix your code

    Do

     ErParam := MySP.Parameter.Add;
     ErParam.Name := '@Error_Number';
     ErParam.DataType := ftInteger; //put your correct type here
     ErParam.Direction := pdInput; //set your direction for the param
    

    etc. Lots more work... do the first way with ADOCommands