I want to programatically create a SQLDataSet in Delphi and use it to execute a Stored Procedure and get the value of an output parameter. Looks easy but I can't make it work.
Here is a dumb stored procedure in SQL Server:
CREATE PROCEDURE [dbo].getValue @x INT OUTPUT
AS
BEGIN
SET @x = 10;
END
Now here is one of the variations that I tried and didn't work:
proc := TSQLDataSet.Create(nil);
proc.SQLConnection := DefaultConnection;
proc.CommandText := 'getValue';
proc.Params.CreateParam(ftInteger, '@x', ptOutput);
proc.Params.ParamByName('@x').Value := 0;
proc.ExecSQL(False);
value := newIdProc.Params.ParamByName('@x').AsInteger;
I thought it would be easy, but there are some registred bugs around this issue.