Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sql Output parameter in asp.net 2

Posted on 2007-04-11
4
Medium Priority
?
844 Views
Last Modified: 2008-01-09
I'm trying to create an output parameter from a stored procedure in sql server and then using it inside of my asp.net 2 application.
This is the code I'm using for a function to retrieve the parameter:
-----------------------------------------------------------------------------------------------------
    Public Sub CreateSessionOrdernr()

        Dim dbConn As New SqlConnection(conn)

        Dim sqlString As String = "WebbCreateSessionOrdernr"
        Dim sqlCmd As New SqlCommand(sqlString, dbConn)
        sqlCmd.CommandType = CommandType.StoredProcedure
        Dim myParameter As New SqlParameter
        myParameter.ParameterName = "@maxnr"
        myParameter.SqlDbType = SqlDbType.Int
        myParameter.Direction = ParameterDirection.Output
        sqlCmd.Parameters.Add(myParameter)

        'sqlCmd.Parameters.AddWithValue("@produktID", _produktID)

        dbConn.Open()


        _maxnr = CInt(sqlCmd.Parameters("@maxnr").Value)

        sqlCmd = Nothing
        dbConn.Close()

    End Sub
-----------------------------------------------------------------

And this is the stored procedure:
------------------------------------------------------------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO



alter           PROCEDURE dbo.WebbCreateSessionOrdernr

      (
      @maxnr int OUTPUT
      )

      
AS
      
      Set @maxnr =  (Select MAX(ordernr) From resk_faktura)
      
      
RETURN
-----------------------------------------------------------------

When I execute it it doesn't retrieve any value but is empty.

How can I get it to work?

Peter
0
Comment
Question by:peternordberg
[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
4 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 18889136
Hi,

Does the stored procedure return anything if you run it from within Query Analyser/SQL Server Management Studio?

Regards,

Lee
0
 

Author Comment

by:peternordberg
ID: 18889145
just that it has successfully created the stored procedure

Peter
0
 
LVL 2

Accepted Solution

by:
balochdude earned 750 total points
ID: 18889155
try this one..

 dbConn.Open()
sqlCmd.ExecuteNonQuery()
_maxnr = CInt(sqlCmd.Parameters("@maxnr").Value)
0
 

Author Comment

by:peternordberg
ID: 18889184
Of course!

That worked!

Thanks Peter!
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

721 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