Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6251325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:35:35+00:00 2026-05-24T13:35:35+00:00

I have a stored procedure: CREATE PROCEDURE [TestProc] AS BEGIN select ‘1a’, ‘1b’ select

  • 0

I have a stored procedure:

CREATE PROCEDURE [TestProc]
AS
BEGIN
   select '1a', '1b'
   select '2a', '2b', '2c'
   select '3a', '3b'
END

If I execute the following query using SQL Management Studio,

exec TestProc

I get 3 result sets:

1. | 1a | 1b |

2. | 2a | 2b | 2c |

3. | 3a | 3b |

But when I use the stored procedure in ASP.NET(VB.NET),

Dim Connection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnToHilmarc").ToString)
Dim Command As New SqlCommand("exec TestProc @First, @Second", Connection)
Dim Reader As SqlDataReader

Command.Parameters.AddWithValue("@First", "Hello")
Command.Parameters.AddWithValue("@Second", "World")

Connection.Open()
Reader = Command.ExecuteReader

While Reader.Read
    Response.Write(Reader(0) & " " & Reader(1) & "<br/>")
End While

Reader.Close()
Connection.Close()

I get only the first result set:

| 1a | 1b |

How can I get the three result sets using SqlDataReader? Or even three SqlDataReader‘s? Or is it possible to get multiple result sets in just one query in VB.NET? Is DataSet my only option? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:35:36+00:00Added an answer on May 24, 2026 at 1:35 pm

    You’ll want to use the NextResult() of SqlDataReader to get the next result set:

    Reader.NextResult();
    

    SqlDataReader.NextResult() returns true if there’s another result set, false otherwise, so you could (in your example code), use the following loop to avoid having 3 sets of code doing essentially the same thing:

    Using Connection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnToHilmarc").ToString())
    
        Dim Command As New SqlCommand("exec TestProc @First, @Second", Connection)
        Dim Reader As SqlDataReader
    
        Command.Parameters.AddWithValue("@First", "Hello")
        Command.Parameters.AddWithValue("@Second", "World")
    
        Connection.Open()
        Reader = Command.ExecuteReader()
    
        While Reader.Read() OrElse (Reader.NextResult() And Reader.Read())
            For i As Integer = 0 To Reader.FieldCount - 1
                Response.Write(Reader(i).ToString()
                Response.Write(" ")
            Next
    
            Response.Write("<br />")
        End While
    
        Reader.Close()
    
    End Using
    

    The OrElse will perform logical short-circuting:

    1. If Reader.Read() returns true, it will read the next row without making a call to Reader.NextResult() (which would advance the reader to the next result and possibly cause loss of data). The And Reader.Read() is there to make sure you get the first row of the next result set.
    2. If Reader.Read() is false, the next expression (Reader.NextResult()) will be evaluated – if it’s true, it’ll process the next result set.
    3. If both are false, the loop is exited.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
I have a stored procedure that consists of a single select query used to
I have a stored procedure for select data between many different sql server, and
I have sql stored procedure which pass and return some values: CREATE PROCEDURE [dbo].[GetMoney]
I have a stored procedure that looks like: CREATE PROCEDURE dbo.usp_TestFilter @AdditionalFilter BIT =
Suppose I have a stored procedure that manages its own transaction CREATE PROCEDURE theProc
I have a stored procedure in SQL 2005. The Stored Procedure is actually creating
I have a stored procedure with the following header: FUNCTION SaveShipment (p_user_id IN INTEGER,
I have a stored procedure that returns multiple tables. How can I execute and
I have a stored procedure CREATE procedure [dbo].[get_unique_identifier] AS DECLARE @ret_val INT UPDATE seq

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.