?
Solved

Using a stored procedure with output parameters in a gridview

Posted on 2006-10-19
3
Medium Priority
?
632 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
1 Comment
 
LVL 10

Accepted Solution

by:
jnhorst earned 2000 total points
ID: 17777569
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

755 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