A better way of passing parameters to a TADOStoredProc (Delphi)

后端 未结 4 887
隐瞒了意图╮
隐瞒了意图╮ 2021-01-02 11:56

I am needing to convert a large amount of SQL queries into stored procedures. I have some code that updates about 20 or 30 values at one time in one Delphi procedure. I can

4条回答
  •  春和景丽
    2021-01-02 12:38

    ADO will create the parameters for you, you just need to call Refresh on the parameters object:

     SP.Connection := SqlConnection; // must be done before setting procedure name
     sp.ProcedureName := 'MyStoredProc';
     sp.Parameters.Refresh; // This will create the parameters for you as defined in SQL Server
     sp.Parameters.ParamByName('@SSN'').Value  := SSN; // params now exist
    

    etc

    If any parameters are output you will need to set them explicitly:

       sp.Parameters.ParamByName('@ReturnValue').Direction := pdInputOutput;
    

提交回复
热议问题