Results 1 to 3 of 3

Thread: [RESOLVED] -- Stored Procedure?

  1. #1

    Thread Starter
    Hyperactive Member crosbj's Avatar
    Join Date
    Oct 2000
    Location
    Michigan
    Posts
    285

    Resolved [RESOLVED] -- Stored Procedure?

    Using MSSQL 2k vb6/classic ado. I've search everywhere for a simple answer to this question from these forums to google. I have a simple sproc on my server with syntax as follows:
    Code:
    CREATE PROCEDURE [stp_Stop9Stat]
     AS SELECT Val11 FROM tblConveyorB3 WHERE(Id=27)
    GO
    I don't want to create a recordset I just want the return value of field 'Val11' from my select statement. I can execute this in Query Analyzer and get the value for 'Val11'. How can I do this with ado? All I get is the @Return_Value which is 0 of course. I just want the stored procedure to return the value from my Select statement without creating a recordset object. Here is the code that executes the sproc from within vb.
    Code:
        Dim objCmd As New ADODB.Command
        With objCmd
            .CommandText = "stp_Stop9Stat"
            .ActiveConnection = DbSQLConn
            .CommandType = adCmdStoredProc
            .Execute
        End With
    I know this is simple, but I can't seem to retrieve the value unless I build a recordset and set it to the Execute statement of my sproc? Am I looking at this wrong or can't I return a value from a sproc without using a recorset?
    -jon
    Last edited by Hack; Mar 31st, 2006 at 01:23 PM. Reason: Added Green Resolved Checkmark Last edited by crosbj : Today at 01:12 PM. Reason: Resolved

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Stored Procedure?

    If you don't want to (or can't) change the SP.... then there's not much you can do. You're going to get a 1 col, 1 row recordset.

    However, if you have the capability to change the SP, then create an OUPUT paramer and return the value that way:

    Code:
    CREATE PROCEDURE [stp_Stop9Stat] 
           @Val int OUTPUT
     AS 
    
    SELECT @Val = Val11 FROM tblConveyorB3 WHERE(Id=27)
    
    GO
    Then update your code to include the parameter:

    VB Code:
    1. Dim objCmd As New ADODB.Command
    2.     With objCmd
    3.         .CommandText = "stp_Stop9Stat"
    4.         .ActiveConnection = DbSQLConn
    5.         .CommandType = adCmdStoredProc
    6. .Parameters.Add .CreateParameter("@Val", adinteger,adparamoutput)
    7.         .Execute
    8. msgbox .Parameters("@Val").Value
    9.     End With

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member crosbj's Avatar
    Join Date
    Oct 2000
    Location
    Michigan
    Posts
    285

    Resolved Re: Stored Procedure?[RESOLVED]

    tg,
    Thanks, that worked. I didn't realize I had to define parameters for field values. I though since the stored procedure returned a row of data I could reference it like a recordset. Adding the OUTPUT parameter worked like a charm! Thanks again.

    -jon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width