🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #5550

Re: Help in using stored procedure in MS SQL 2000

#5550
From: Peter Falconer
Date: Tue, 10 Apr 2001 01:15
118 lines
3899 bytes
Chris,

I assume that you are trying to return @Ref and your code should read
CREATE PROCEDURE GetLastSupplierRef
  @Ref INT
AS
SET NOCOUNT ON
  SELECT @Ref = MAX(Supplier_Ref)
    FROM TicSuppliers
IF (@Ref = NULL)
BEGIN
  SET @Ref = 0
END
RETURN @Ref //rather than RETURN 0
GO

Theoretically this should work if you have defined parameter 0 as
direction = pdReturnValue but I've always had trouble with return
parameters. What I have been able to get to work is to declare the
parameter as Output (both in the stored proc and in Builder)
try
CREATE PROCEDURE GetLastSupplierRef
  @Ref INT Output
AS
SET NOCOUNT ON
  SET @Ref = select(MAX(Supplier_Ref)
    FROM TicSuppliers)
IF (@Ref = NULL)
BEGIN
  SET @Ref = 0
END
GO

Assuming the storedproc name and param type and direction has been set
up in the IDE the Builder code is something like ...

int iLastRef ;
try
  {
    ADOStoredProc1->ExecProc();   //should use ExecProc as not
returning a selection
    iLastRef = ADOStoredProc1->Parameters->Items[0]->Value;
  }
  catch(EDatabaseError &E) // does not catch error
{
// how do you catch and decode the error?
    ShowMessage("Error executing GetLastSupplierRef. "+E.Message);
}

(I am using SQL Server 7, but assume that there are no relevant
differences here)


Chris Noble wrote in message <3acaea3b_1@dnews>...
>I am having problems in using a stored procedure in MS SQL 2000
(personal
>edition) using the Enterprise version Builder 5 with the latest
patches
>applied on a Windows 2000 workstation. I have installed MDAC 2.6 and
updated
>the help for ADO Express (which still seem to be out of date!)
>
>The ADO connection string works and I can access the data in the
tables.
>
>The stored procedure will look up the last supplier reference
(integer) and
>return its value or 0 if there are no entries in the column. I can
find ways
>round this by not using stored procedures but I would like to know
how do
>it. Please take note Borland!
>
>The stored procedure is listed at the end:
>
>I have failed to access the procedure and get OLE error 80040E 14
using
>either the object inspector (design time) or the following code (run
time):
>
>ADOStoredProc1->Close();
>ADOStoredProc1->ProcedureName = "GetLastSupplierRef";
>try
>  {
>    ADOStoredProc1->Open(); // also tried ExecProc()
>  }
>  catch(EDatabaseError &E) // does not catch error
>{
>// how do you catch and decode the error?
>}
>
>Are there any examples of how to use stored procedures with SQL 2000
using
>parameters and are there any updates to the documentation which
currently
>contains errors? eg ADOStoredProc1->SQL->Text = "ShowPurebreds";
there is no
>SQL property in TADOStoredPROC.
>Thanks for any help
>
>Chris Noble
>
>CREATE PROCEDURE GetLastSupplierRef
>  @Ref INT
>AS
>SET NOCOUNT ON
>  SELECT @Ref = MAX(Supplier_Ref)
>    FROM TicSuppliers
>IF (@Ref = NULL)
>BEGIN
>  SET @Ref = 0
>END
>RETURN 0
>GO
>
>
>
>
Technical Details
Message-ID: <3ad25e34_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews
References: <3acaea3b_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,fec455fa27bb194e
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2001-04-09 18:26:01 PST
From: "Peter Falconer" <Peter.Falconer@fsunion.org.au>
Newsgroups: borland.public.cppbuilder.database.ado
References: <3acaea3b_1@dnews>
Subject: Re: Help in using stored procedure in MS SQL 2000
Date: Tue, 10 Apr 2001 11:15:42 +1000
Lines: 119
Organization: FSU
MIME-Version: 1.0
Content-Type: text/plain;
 charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft Outlook Express 4.72.3612.1700
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700
NNTP-Posting-Host: 203.55.24.2
Message-ID: <3ad25e34_1@dnews>
X-Trace: dnews 986865204 203.55.24.2 (9 Apr 2001 18:13:24 -0700)
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews