Solved

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

Posted on 2009-06-27
4
506 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 63 total points
Comment Utility
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 62 total points
Comment Utility
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
Comment Utility
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
Comment Utility
These two responses have provided me with useful information.

Thanks.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now