Parameter of stored procedure not found

别说谁变了你拦得住时间么 提交于 2019-12-25 13:12:08

问题


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

but I can't understand why I get an error


回答1:


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



来源:https://stackoverflow.com/questions/31903397/parameter-of-stored-procedure-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!