D
Damien Foggon
Struggling with a return value problem from a stored procedure. Any one
any ideas?
I have the following stored procedure:
CREATE PROCEDURE [dbo].[stpGetPublisherBooks]
AS
DECLARE @rows int
SELECT Book.BookID, Book.BookTitle, Book.BookMainTopic,
Publisher.PublisherName
FROM Book
INNER JOIN Publisher on Book.BookPublisherID = Publisher.PublisherID
ORDER BY Book.BookTitle
SET @rows = @@ROWCOUNT
RETURN (@rows)
If I execute this in Query Analyzer I get the correct result reuturned
(5 in fact). But if I do the following I always get 0 returned:
// add the return value
SqlParameter myReturnValue = new SqlParameter();
myReturnValue.ParameterName = "@RETURN";
myReturnValue.SqlDbType = SqlDbType.Int;
myReturnValue.Direction = ParameterDirection.ReturnValue;
myCommand.Parameters.Add (myReturnValue);
myConnection.Open();
// execute the command and bind to the DataGrid
SqlDataReader myReader = myCommand.ExecuteReader();
DataGrid1.DataSource = myReader;
DataGrid1.DataBind();
myReader.Close();
// now get the output parameter
Label1.Text = Convert.ToString(myCommand.Parameters["@RETURN"].Value);
any ideas?
I have the following stored procedure:
CREATE PROCEDURE [dbo].[stpGetPublisherBooks]
AS
DECLARE @rows int
SELECT Book.BookID, Book.BookTitle, Book.BookMainTopic,
Publisher.PublisherName
FROM Book
INNER JOIN Publisher on Book.BookPublisherID = Publisher.PublisherID
ORDER BY Book.BookTitle
SET @rows = @@ROWCOUNT
RETURN (@rows)
If I execute this in Query Analyzer I get the correct result reuturned
(5 in fact). But if I do the following I always get 0 returned:
// add the return value
SqlParameter myReturnValue = new SqlParameter();
myReturnValue.ParameterName = "@RETURN";
myReturnValue.SqlDbType = SqlDbType.Int;
myReturnValue.Direction = ParameterDirection.ReturnValue;
myCommand.Parameters.Add (myReturnValue);
myConnection.Open();
// execute the command and bind to the DataGrid
SqlDataReader myReader = myCommand.ExecuteReader();
DataGrid1.DataSource = myReader;
DataGrid1.DataBind();
myReader.Close();
// now get the output parameter
Label1.Text = Convert.ToString(myCommand.Parameters["@RETURN"].Value);