?
Solved

Using a stored procedure with output parameters in a gridview

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

765 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