Solved

Sql Output parameter in asp.net 2

Posted on 2007-04-11
4
840 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
  • 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 250 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TSQL query to generate xml 4 34
Help in Bulk Insert 9 33
T-SQL Default value in Select? 5 26
SQL Server Connection String through a VPN 8 23
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

772 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