找不到存储过程的参数

Parameter of stored procedure not found

我使用以下代码调用我的存储过程,使用 TADOStoredProc 类型

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;

参数 @Error_Number 是使用 SQL Server Management Studio 的存储过程 UpdateErrors 的一部分,我添加截图以进行确认

但我不明白为什么会出现错误

只需使用 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;

如果您想修复代码

 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

等还有很多工作...使用 ADOCommands

执行第一种方法