Page 1 of 1

TMSStoredProc

Posted: Wed 27 Sep 2006 14:48
by haci
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,

Posted: Wed 27 Sep 2006 15:49
by Antaeus
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; 

Posted: Thu 28 Sep 2006 05:28
by haci
Thank you, for your help.