Solved

Sql Output parameter in asp.net 2

Posted on 2007-04-11
4
838 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now