代码之家  ›  专栏  ›  技术社区  ›  user1769184

未找到存储过程的参数

  •  0
  • user1769184  · 技术社区  · 10 年前

    我使用以下代码调用存储过程 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 是存储过程的一部分 UpdateErrors 使用SQLServerManagementStudio,我添加了用于确认的截图

    enter image description here

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

    1 回复  |  直到 10 年前
        1
  •  2
  •   kobik    10 年前

    只需使用TADOC命令

      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做第一种方法