Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Avoiding multiple result sets in a SP when using ExecuteReader and datareader

Posted on 2009-06-27
4
Medium Priority
?
519 Views
Last Modified: 2013-12-17
Hello

I have a c# datareader.read method intended to read some rows from just one table in a sql server 2005 DB by means of a stored procedure.

The SP has a final select statement which provides the desired data for the read method, but it has also some other select staments inside which are executed previously to the final select statement which provides the data.

And it seems as if there are not an only result set, but some other ones, one per each select statement in the SP. And this affects the read method.

How can I hide those select statements in the SP distinct from the the final one, in such a way they don't generate result sets which are undesirably readed by the read method?

Thanks in advance,

Juarrero
0
Comment
Question by:juarrero
4 Comments
 
LVL 31

Accepted Solution

by:
RiteshShah earned 252 total points
ID: 24726996
as soon as you execute your command and store your result of SP in dataset, you can refer all your select statement like table[0], table[1] etc. if you have two select statement and you want to have result of only second SELECT, assign table[1] in datareader
0
 
LVL 22

Assisted Solution

by:8080_Diver
8080_Diver earned 248 total points
ID: 24728125
Alternatively, you could have the preceding SELECT statements select into variables of some sort (e.g. individual variables for individual results such as aggregates or, even, in-memory tables) and then work with the variables in the process of completing the SP.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24728391
Why don't you post the stored procedure?  More than likely all the is requires is SET NOCOUNT ON at the start of the Stored Procedure.  But without seeing the Stored Procedure it is impossible to say for sure.
0
 

Author Closing Comment

by:juarrero
ID: 31597209
These two responses have provided me with useful information.

Thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 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