?
Solved

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

Posted on 2008-10-15
4
Medium Priority
?
912 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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.
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 keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

771 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