Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 9th, 2004, 09:39 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old February 9th, 2004, 09:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
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
Reply With Quote
  #3 (permalink)  
Old February 9th, 2004, 09:45 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
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
Reply With Quote
  #4 (permalink)  
Old February 9th, 2004, 09:56 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
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
Reply With Quote
  #5 (permalink)  
Old February 9th, 2004, 10:09 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem Solved.

Thanks anyway.

ohiggs
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:17 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.