Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2004, 09:39 PM
Registered User
 
Join Date: Feb 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL output parameters

I'm using VB6, SQL 2000, ADO 2.7 library, Win2000. I have code in a procedure that utilizes the CreateParameter, Append method of the command object to execute a stored proc. I have the parameter declared as OUPTUT in my stored proc.
 The procedure runs and inserts the record but my output parameter keeps coming back 0. :

    ---- some code here -----

    Set Param = .CreateParameter(mREQ_ID, 3, adParamOutput, 0, REQ_ID)
    .Parameters.Append Param
    Param.Value = REQ_ID

    ---- some code here -----

    Set rs = .Execute

    REQ_ID = Val("" & .Parameters(0).Value)

Can anyone assist?



ohiggs
 
Old February 9th, 2004, 09:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

You have to read the entire recordset and close it before the OUTPUT parameter value becomes available.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old February 9th, 2004, 09:45 PM
Registered User
 
Join Date: Feb 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, the stored proc only inserts or updates. I don't read anything.

ohiggs
 
Old February 9th, 2004, 09:56 PM
Registered User
 
Join Date: Feb 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The stores proc is:

CREATE PROCEDURE [DBO].[PRC_WRITE_PURCHASEREQ]

    @mREQ_ID INT OUTPUT,
    @mAppl_ID INT,
    @mDept_ID INT,
    @mBldg_ID INT,
    @mTitle VARCHAR (50),
    @mFName VARCHAR (50),
    @mLName VARCHAR (50),
    @mWorkPhone VARCHAR (20),
    @mMailCode VARCHAR (10),
    @mRoomNo VARCHAR (10),
    @mPN_SW INT,
    @mPN_HW INT,
    @mPN_Other INT,
    @mPN_OtherDesc VARCHAR(150),
    @mDateNeeded VARCHAR (50),
    @mVendor_ID INT,
    @mProdType CHAR(20),
    @mCost_Center INT,
    @mDirector_ID INT

AS
    UPDATE TBL_PURCHASEREQUEST
    SET Appl_ID = @mAppl_ID,
            Dept_ID = @mDept_ID,
            Bldg_ID = @mDept_ID,
            Title = @mTitle,
            FName = @mFName,
            LName = @mLName,
            WorkPhone = @mWorkPhone,
            MailCode = @mMailCode,
            RoomNo = @mRoomNo,
            PN_SW = @mPN_SW,
            PN_HW = @mPN_HW,
            PN_Other = @mPN_Other,
            PN_OtherDesc = @mPN_OtherDesc,
            RequestDate = @mDateNeeded,
            Vendor_ID = @mVendor_ID,
            ProdType = @mProdType,
            Cost_Center = @mCost_Center,
            Director_ID = @mDirector_ID,
            UpdateDate = GetDate(),
            UpdateUser = SYSTEM_USER
    WHERE Req_ID = @mREQ_ID

    IF @@ROWCOUNT = 0

        BEGIN
            INSERT TBL_PURCHASEREQUEST(Appl_ID, Dept_ID,Bldg_ID,Title,FName,
                LName, WorkPhone, MailCode, RoomNo, PN_SW, PN_HW,PN_Other, PN_OtherDesc,
                RequestDate, Vendor_ID, ProdType, Cost_Center, Director_ID)

            VALUES(@mAppl_ID, @mDept_ID, @mBldg_ID, @mTitle, @mFName,
                @mLName, @mWorkPhone, @mMailCode, @mRoomNo, @mPN_SW, @mPN_HW, @mPN_Other, @mPN_OtherDesc,
                @mDateNeeded, @mVendor_ID, @mProdType, @mCost_Center, @mDirector_ID)

            SELECT @mREQ_ID = @@IDENTITY
        END

ohiggs
 
Old February 9th, 2004, 10:09 PM
Registered User
 
Join Date: Feb 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem Solved.

Thanks anyway.

ohiggs





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Parameters: I can't be this stupid... raysot BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 13 May 20th, 2010 07:28 PM
Chapter 6 "Using SQL Output Parameters..." burkecrosby BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 22 February 10th, 2010 05:33 PM
output parameters with the objectdatasource trancehead ASP.NET 2.0 Professional 2 August 25th, 2008 12:41 PM
Output Parameters Bob Bedell SQL Server 2000 2 March 25th, 2006 06:32 AM
OUTPUT Parameters saulodet ADO.NET 0 May 14th, 2004 10:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.