473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Stored procedure

Hi,

I'm a student and I have the following working example that troubles
me (in SQL Server 2005):

CREATE PROCEDURE dbo.CustomersOrderHistory
( @Firstname varchar(7) OUTPUT)
AS
SELECT dbo.Customers.Firstname, dbo.Orders.Orderdate,
dbo.Orderdetails.Orderamount, dbo.Orderdetails.Orderprice,
dbo.Orderdetails.Orderdiscount,
dbo.Items.Itemname,dbo.Orderdetails.Orderamount
* dbo.Orderdetails.Orderprice AS Ordersum
FROM dbo.Orderdetails INNER JOIN
dbo.Items ON dbo.Orderdetails.ItemID =
dbo.Items.ItemID INNER JOIN
dbo.Orders ON dbo.Orderdetails.OrderID =
dbo.Orders.OrderID INNER JOIN
dbo.Customers ON dbo.Orders.Customer =
dbo.Customers.CustomerID
WHERE dbo.Customers.Firstname LIKE @Firstname
ORDER BY dbo.Orders.Orderdate
/* SET NOCOUNT ON */
RETURN @Firstname

Now I'm calling this stored procedure from C# code on an aspx page.
The @Firstname parameter is supposed to be used against the user who
logges in to his customerpage. When the customer page loads his
orderhistory will be filled into a gridview through a datareader.

However, I'm a little uncertain whether I should use OUTPUT or INPUT
as a parameter.

This works fine if I'm using a dataset, but I'd like to use a
datareader because I think it is less consuming of resources.

As it is now the stored procedure return nothing and I wonder where I
go wrong.

Any tip?

Thank you in advance.

Me.Name

Feb 20 '07 #1
2 6369
However, I'm a little uncertain whether I should use OUTPUT or INPUT
as a parameter.
Use an input parameter (the default) to provide the search value to the
proc.
This works fine if I'm using a dataset, but I'd like to use a
datareader because I think it is less consuming of resources.
A DataReader can be used to process the stored procedure result set without
changing the stored procedure code.

There are 3 basic ways that a stored procedure can return data: OUTPUT
parameter, result set (SELECT) and the return code (RETURN). The Best
Practice is to use the return code only to indicate success or failure.
OUTPUT parameters are typically an option only when scalar values returned.
In your case, you need to use a result set because many rows can be
potentially returned. For example:

CREATE PROCEDURE dbo.CustomersOrderHistory
@Firstname varchar(7)
AS

SELECT ...
WHERE dbo.Customers.Firstname LIKE @Firstname

RETURN @@ERROR
GO

Note that parameters are accessed via the Command object rather than a
DataReader. The stored procedure return code is exposed in .Net as a
parameter with direction ReturnValue.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Krij" <gs***@start.nowrote in message
news:11*********************@v45g2000cwv.googlegro ups.com...
Hi,

I'm a student and I have the following working example that troubles
me (in SQL Server 2005):

CREATE PROCEDURE dbo.CustomersOrderHistory
( @Firstname varchar(7) OUTPUT)
AS
SELECT dbo.Customers.Firstname, dbo.Orders.Orderdate,
dbo.Orderdetails.Orderamount, dbo.Orderdetails.Orderprice,
dbo.Orderdetails.Orderdiscount,
dbo.Items.Itemname,dbo.Orderdetails.Orderamount
* dbo.Orderdetails.Orderprice AS Ordersum
FROM dbo.Orderdetails INNER JOIN
dbo.Items ON dbo.Orderdetails.ItemID =
dbo.Items.ItemID INNER JOIN
dbo.Orders ON dbo.Orderdetails.OrderID =
dbo.Orders.OrderID INNER JOIN
dbo.Customers ON dbo.Orders.Customer =
dbo.Customers.CustomerID
WHERE dbo.Customers.Firstname LIKE @Firstname
ORDER BY dbo.Orders.Orderdate
/* SET NOCOUNT ON */
RETURN @Firstname

Now I'm calling this stored procedure from C# code on an aspx page.
The @Firstname parameter is supposed to be used against the user who
logges in to his customerpage. When the customer page loads his
orderhistory will be filled into a gridview through a datareader.

However, I'm a little uncertain whether I should use OUTPUT or INPUT
as a parameter.

This works fine if I'm using a dataset, but I'd like to use a
datareader because I think it is less consuming of resources.

As it is now the stored procedure return nothing and I wonder where I
go wrong.

Any tip?

Thank you in advance.

Me.Name
Feb 20 '07 #2
On 20 Feb, 14:41, "Dan Guzman" <guzma...@nospam-online.sbcglobal.net>
wrote:
However, I'm a little uncertain whether I should use OUTPUT or INPUT
as a parameter.

Use an input parameter (the default) to provide the search value to the
proc.
This works fine if I'm using a dataset, but I'd like to use a
datareader because I think it is less consuming of resources.

A DataReader can be used to process the stored procedure result set without
changing the stored procedure code.

There are 3 basic ways that a stored procedure can return data: OUTPUT
parameter, result set (SELECT) and the return code (RETURN). The Best
Practice is to use the return code only to indicate success or failure.
OUTPUT parameters are typically an option only when scalar values returned.
In your case, you need to use a result set because many rows can be
potentially returned. For example:

CREATE PROCEDURE dbo.CustomersOrderHistory
@Firstname varchar(7)
AS

SELECT ...
WHERE dbo.Customers.Firstname LIKE @Firstname

RETURN @@ERROR
GO

Note that parameters are accessed via the Command object rather than a
DataReader. The stored procedure return code is exposed in .Net as a
parameter with direction ReturnValue.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Krij" <g...@start.nowrote in message

news:11*********************@v45g2000cwv.googlegro ups.com...
Hi,
I'm a student and I have the following working example that troubles
me (in SQL Server 2005):
CREATE PROCEDURE dbo.CustomersOrderHistory
( @Firstname varchar(7) OUTPUT)
AS
SELECT dbo.Customers.Firstname, dbo.Orders.Orderdate,
dbo.Orderdetails.Orderamount, dbo.Orderdetails.Orderprice,
dbo.Orderdetails.Orderdiscount,
dbo.Items.Itemname,dbo.Orderdetails.Orderamount
* dbo.Orderdetails.Orderprice AS Ordersum
FROM dbo.Orderdetails INNER JOIN
dbo.Items ON dbo.Orderdetails.ItemID =
dbo.Items.ItemID INNER JOIN
dbo.Orders ON dbo.Orderdetails.OrderID =
dbo.Orders.OrderID INNER JOIN
dbo.Customers ON dbo.Orders.Customer =
dbo.Customers.CustomerID
WHERE dbo.Customers.Firstname LIKE @Firstname
ORDER BY dbo.Orders.Orderdate
/* SET NOCOUNT ON */
RETURN @Firstname
Now I'm calling this stored procedure from C# code on an aspx page.
The @Firstname parameter is supposed to be used against the user who
logges in to his customerpage. When the customer page loads his
orderhistory will be filled into a gridview through a datareader.
However, I'm a little uncertain whether I should use OUTPUT or INPUT
as a parameter.
This works fine if I'm using a dataset, but I'd like to use a
datareader because I think it is less consuming of resources.
As it is now the stored procedure return nothing and I wonder where I
go wrong.
Any tip?
Thank you in advance.
Me.Name
Thanks :-)

Feb 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
3
by: kd | last post by:
Hi All, How to debug a stored procedure? Thanks, kd
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.