Solved

Using a stored procedure with output parameters in a gridview

Posted on 2006-10-19
3
579 Views
Last Modified: 2008-03-17
He there:

I have a stored procedure that has some input parameters and some output parameters. The input parameters are supposed to be drawn from two user controls (hiddenfields) and one is supposed to be taken from the querystring. The output parameters are supposed to be viewed in the detailsview that displays my data.

However I have no luck doing this. It seems as if I cannot display the output parameters as rows in my gridview, and it seems I have to give my output parameters a value before the stored procedure is executed - which is pointless, because this is not relevant.

Any ideas?

The stored procedure looks like this:
ALTER PROCEDURE dbo.ejNotifiedTilmeldinger

            @antal int OUTPUT,
            @not_notified bit output,
            @dato varchar(30),
            @kursus_id int,
            @profil_id int

AS
      declare @antal2 int
      
      SET @antal=0
      set @antal2=0
      set @not_notified='false'
      
      select @antal = count(*)
      from kursusTilmelding
      WHERE kursusTilmelding.dato = @dato
      AND        kursusTilmelding.kursus_id=@kursus_id
      AND        kursusTilmelding.profil_id = @profil_id
      AND        kursusTilmelding.slettet = 'false'
      and   kursusTilmelding.notified = 'false'
      
      select @antal2 = count(*)
      FROM  undertilmeldingNy
      WHERE undertilmeldingNy.dato = @dato
      AND        undertilmeldingNy.kursus_id = @kursus_id
      AND   undertilmeldingNy.slettet = 'false'
      AND        undertilmeldingNy.betalingsprofil_id = @profil_id
      and   undertilmeldingNy.notified = 'false'
            
      set @antal=@antal+@antal2
      if @antal>0 set @not_notified='true'

RETURN @antal
0
Comment
Question by:RunePerstrup
3 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 500 total points
Comment Utility
The problem is probably that when you construct your SqlCommand, the output params are not identfied as such in the Direction property.  If you are using VS2003, try this:

Open the Server Explorer and create a connection to your database.  Show your stored procedures and then drag the one you want to use onto your web page when it is in design mode.  You should see an icon appear in the component tray below the page in design view.  This represents a SqlCommand object, the code for which has been written by the IDE in the "Web Form Designer generated code" section of your code page.

You can right click this icon and select Properties.  Inspect the Parameters collection and you will see that your output params have been declare as such.

Set the input params in code, ExecuteNonQuery() against the command, and then get the values from the output parameters.

John
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

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

9 Experts available now in Live!

Get 1:1 Help Now