Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now