Solved

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

Posted on 2008-10-15
4
911 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

717 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