TMSStoredProc

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
haci
Posts: 11
Joined: Tue 17 Jan 2006 11:32

TMSStoredProc

Post by haci » Wed 27 Sep 2006 14:48

I create a stored procedue in SQL Server 2000 called "SDAC_FindUser"

and it's code like this :

CREATE PROCEDURE SDAC_FindUser
@PRKEY int
AS

SELECT * FROM Persons
WHERE PRKEY = @PRKEY

RETURN @PRKEY
GO

At the Delphi part, i wrote this code, i used TMSStoredProc component;

with DM1.MSFindUser do
begin
Params.Clear;
Params.CreateParam(ftInteger, 'PRKEY', ptInput);
Params.ParamByName('PRKEY').AsInteger := inpval;
ExecProc;

Returned := Integer(Params.ParamByName('RETURN_VALUE').Value);
ShowMessage(IntToStr(returned));
end;

When i try to run this code compiler gives this error message :

"No Value Given for one or more required parameters."

Please, tell me where is my mistake ? I didn't find my mistake.
Thank you,

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 27 Sep 2006 15:49

You should not create parameters manually. They are created automatically after setting StoredProcName. So, following code should work:

Code: Select all

  with DM1.MSFindUser do begin 
    StoredProcName := 'SDAC_FindUser';
    Params.ParamByName('PRKEY').AsInteger := inpval; 
    ExecProc; 
    Returned := Integer(Params.ParamByName('RETURN_VALUE').Value); 
    ShowMessage(IntToStr(returned)); 
  end; 
Your code does not work because you have not created the second parameter: 'RETURN_VALUE' to return value from the server. So, following code should work too:

Code: Select all

  with DM1.MSFindUser do begin 
    Params.Clear; 
    Params.CreateParam(ftInteger, 'RETURN_VALUE', ptOutPut); 
    Params.CreateParam(ftInteger, 'PRKEY', ptInput); 
    Params.ParamByName('PRKEY').AsInteger := inpval; 
    ExecProc; 
    Returned := Integer(Params.ParamByName('RETURN_VALUE').Value); 
    ShowMessage(IntToStr(returned)); 
  end; 

haci
Posts: 11
Joined: Tue 17 Jan 2006 11:32

Post by haci » Thu 28 Sep 2006 05:28

Thank you, for your help.

Post Reply