Solved

Sql Output parameter in asp.net 2

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Load Fact table in SQL Server SSIS package 14 47
mssql 7 32
sql trace 4 29
Report 8 27
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

752 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