Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
General
»
Stored procedures with output parameters
Stored procedures with output parameters
Rate Topic
Display Mode
Topic Options
Author
Message
dobinf
dobinf
Posted Monday, December 29, 2008 5:10 AM
Forum Newbie
Group: General Forum Members
Last Login: Wednesday, October 31, 2012 10:21 AM
Points: 7,
Visits: 13
Hello everyone,
I am using a stored procedure with output parameters, But i get the value of the output parameter as Zero. I have checked in query analyser and i get a value greater than zero,but in code i get the value as zero, Can anyone help me. the code is as follows
conn.Open();
SqlDataReader dr;
SqlCommand cmd = new SqlCommand("GetAllImages", conn);
cmd.CommandType = CommandType.StoredProcedure;
//Create a SqlParameter object to hold the output parameter value
SqlParameter img_count = new SqlParameter("@img_count",SqlDbType.Int);
//IMPORTANT - must set Direction as Output
img_count.Direction = ParameterDirection.Output;
cmd.Parameters.Add(img_count);
dr = cmd.ExecuteReader();
int intCountOfImages = Convert.ToInt32(img_count.Value);
The SQL statement is as follows:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[GetAllImages]
@img_count int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SET @img_count=(Select count(img_id) from images);
SELECT img_name,img_path from images;
END
ANy suggestions would be greatly appreciated, Thankyou in Advance
Regards,
Judef
Post #626488
Dugi
Dugi
Posted Monday, December 29, 2008 6:24 AM
Ten Centuries
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 1:48 AM
Points: 1,252,
Visits: 3,367
Don't do double posts!
The original is
here
:
Steve it should be closed!
============================================================
SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #626536
dobinf
dobinf
Posted Monday, December 29, 2008 6:38 AM
Forum Newbie
Group: General Forum Members
Last Login: Wednesday, October 31, 2012 10:21 AM
Points: 7,
Visits: 13
ok I am new to this site. Can you please solve my problem?
Post #626546
Dugi
Dugi
Posted Monday, December 29, 2008 6:44 AM
Ten Centuries
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 1:48 AM
Points: 1,252,
Visits: 3,367
dobinf (12/29/2008)
ok I am new to this site. Can you please solve my problem?
Sure that you are new here and you are welcome ... but please read carefully all the sections in board and do the posts in right sections!
Someone will respond to your problem as soon as possible!
Success!
============================================================
SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #626551
Matt Miller (#4)
Matt Miller (#4)
Posted Monday, December 29, 2008 7:41 AM
SSCertifiable
Group: General Forum Members
Last Login: Yesterday @ 6:49 PM
Points: 6,998,
Visits: 13,946
ExecuteReader is a little funky when dealing with output parameters. The output parameters are available only AFTER the recordset is used and closed. From MSDN:
Using a DataReader to Process the RETURN Value and OUTPUT Parameters
This same query can be executed directly with the Command.ExecuteReader (or ExecuteNonQuery if you don't have a rowset to process), but there are several other steps you'll need to take to process the returned values. Remember, you'll have to complete processing for all rowsets before attempting to capture the Return value or OUTPUT parameters. The following code shows how to use the ExecuteReader and a loop to process the rowsets, and then capture the Return value and OUTPUT parameters. You'll find that OUTPUT parameters (even a lot of them) can be handled far faster than even a single row of data returned by a SELECT
You may be better off using a dataset instead - the output parameters handling is more straightforward.
http://msdn.microsoft.com/en-us/library/ms971497.aspx#gazoutas_topic4
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Post #626560
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.