Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-15
4
Medium Priority
?
915 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

636 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