[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delphi 7 :: Executing MS SQL 2005 Stored Procedure with Output Variabel

Posted on 2008-10-15
4
Medium Priority
?
916 Views
Last Modified: 2013-11-23
Dear Experts,

I can't find a working example of how to execute a MS SQL 2005 stored procedure which returns an output variable within Delphi 7 code.

Please show me an example.

Thanks.
0
Comment
Question by:Marius0188
  • 2
  • 2
4 Comments
 

Author Comment

by:Marius0188
ID: 22719096
Please see my Delphi code below, when running this code I receive the following Delphi runtime error message: see attached image...
var
  sResult :String;
begin
  ADOStoredProc1.ProcedureName := 'spGetTritonPartTypes';
  ADOStoredProc1.Parameters.Refresh;
  ADOStoredProc1.Parameters.ParamValues['@po']  := '5000';
  ADOStoredProc1.ExecProc;
  sResult := ADOStoredProc1.Parameters.ParamValues['@output'];
 
  ShowMessage(sResult);
end;

Open in new window

sp-error.jpg
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 22729346
use a TADOQuery and do it like this

ADOQuery1.SQL.Text :=  'set nocount on' + #13#10 +
                                          'declare @res int ' + #13#10 +
                                          'exec @spGetTritonPartTypes :po, @output OUTPUT ' + #13#10
                                          'set nocount off ' + #13#10 +
                                          'select @res as res';

with adoquery1.parameters.parambyname('po') do
begin
  paramtype := ftInteger;
  value := 5000;
end;
AdoQuery1.Open;
ShowMessage(ADOQuery1.FieldByName('res').AsInteger);

something like that anyway, I'm not near my dev p.c.
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 2000 total points
ID: 22729352
oops, typo

ADOQuery1.SQL.Text :=  'set nocount on' + #13#10 +
                                          'declare @res int ' + #13#10 +
                                          'exec @spGetTritonPartTypes :po, @res OUTPUT ' + #13#10
                                          'set nocount off ' + #13#10 +
                                          'select @res as res';
0
 

Author Comment

by:Marius0188
ID: 22739206
Thanks for the reply.
Just 1 fix and it is working 100%.

 "@spGetTritonPartTypes"
 shoud be: "spGetTritonPartTypes"

Thanks again.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question