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 1109689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:16:37+00:00 2026-05-17T02:16:37+00:00

How to handle multiple ResultSets, each with multiple Rows? The call to NextResult() breaks

  • 0

How to handle multiple ResultSets, each with multiple Rows?
The call to NextResult() breaks the while loop.

Some of my SPs return multiple ResultSets. I’m handling these with NextResult() but when I do and my SP only has a single ResultSet, I see the while loop with Read() finishes leaving me with only the first Row.

Without the call to NextResult() I get all the rows for the first ResultSet but of course the second and subsequent ResultSets don’t get processed?

using (IDataReader reader = storedProcedure.ExecuteReader(
    CommandBehavior.CloseConnection, parameterNames as string[], arguments))
{
    while (reader.Read())
    {
        ArrayList row = new ArrayList();
        for (int j = 0; j < reader.FieldCount; ++j)
        {
            object rowValue = reader.GetValue(j);

            row.Add(rowValue);
        }

        reader.NextResult();//next resultset, breaks out of the  while
    }
}
  • 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-17T02:16:38+00:00Added an answer on May 17, 2026 at 2:16 am

    You need to create two nested loops.

    • The outer loop should iterate over result sets and should have NextResult at the end
    • The inner loop should iterate over rows in a result set and should have Read at the beginning.

    Something like:

    using (IDataReader reader = ...) { 
      // Process all result sets
      do {
        // Process all elements in the current result set
        while (reader.Read()) { 
          ArrayList row = new ArrayList(); 
          for (int j = 0; j < reader.FieldCount; ++j) { 
            object rowValue = reader.GetValue(j); 
            row.Add(rowValue); 
          } 
          // TODO: Do something with 'row'
        }
      } while (reader.NextResult())
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DocumentsController#common_query can handle multiple different request styles. i.e. all docs in batch 4 or
First of all, I am a complete Java NOOB. I want to handle multiple
How to handle personal stress caused by utterly incompetent and lazy co-workers?
Given a handle of type HWND is it possible to confirm that the handle
Is it possible to handle POSIX signals within the Java Virtual Machine? At least
I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using
Does your software handle newline characters from other systems? Linux/BSD linefeed ^J 10 x0A
I have the handle of process 'A' on a Pocket PC 2003 device. I
How does one handle a DateTime with a NOT NULL ? I want to
How does C handle converting between integers and characters? Say you've declared an integer

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.