ASP.Net SQL Server Stored Procedure

Hi Experts,

Consider the Stored Procedure,


Select * from Table1

Select Count(*) from Table2



Now, this Stored Procedure is returning 2 values ( DataTable and the Count), hence how could this be handled in the .Net Application.
I have read on some websites that, a stored Procedure is like a function and can only return one value/datatable.

Does the above the Stored Procedure return 2 datatables?

Please help me clarify, how could I use the above Stored Procedure in the front-end like C#/VB.Net


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DBAduck - Ben MillerPrincipal ConsultantCommented:
The questions listed above don't seem to address your issue.

The thing you need to know is depending on what you want to use to get the data back.

The bottom line is that when you have a stored procedure return 2 rowsets, which is what you are doing in your example, is that these are some of your options.

DataSet ds = new DataSet();

SqlConnection sql = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand("dbo.somestoredprocedure", sql);
SqlDataAdapter da = new SqlDataAdapter(cmd);

if(da.Tables.Count > 1)
    // Table 1 is ds.Tables[0] and Table 2 is ds.Tables[1].

If you use a DataReader then you can use the DataReader.NextResultSet() to get the next result into place, then you can Read just like any resultset.

Let me know if you need any more information.
Ben Miller

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vad2319Author Commented:
Thank you Experts. Nauman, your answer was also very nice, but dbaduck's answer was what I was looking for.
Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.