Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using a stored procedure with output parameters in a gridview

Posted on 2006-10-19
3
Medium Priority
?
629 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
[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
3 Comments
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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