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

  • SEARCH
  • Home
  • 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 8043419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:53:43+00:00 2026-06-05T04:53:43+00:00

I wanted to use nested SqlDataReader in the code below but I couldn’t make

  • 0

I wanted to use nested SqlDataReader in the code below but I couldn’t make it.I get “System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first” with the code. Any Suggestions

            c = "select user_Reps.rep_key,Officers.Officer_Name from user_Reps left join Officers on user_Reps.rep_key = Officers.Officer_code where [user_key]="+userCode;
            if (c == null)
                c = sr.ReadToEnd();
            try
            {

                SqlCommand cmd = new SqlCommand(c, cn);
                cn.Open();
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                SqlDataReader rdr2;
                while (rdr.Read())
                {
                    string c2 = "select Active_Clients.Clients_code,Active_Clients.Clients_Name,Active_Clients.Geo_code  from Active_Clients where Active_Clients.[Officer_code] =" + rdr.GetValue(0) + " order by Clients_Name";
                    SqlCommand cmd2 = new SqlCommand(c2, cn);

                    rdr2 = cmd2.ExecuteReader(CommandBehavior.CloseConnection);


                    Dictionary<string, object> d = new Dictionary<string, object>(rdr.FieldCount+rdr2.FieldCount);
                    while (rdr2.Read())
                    {
                        int i = 0;
                        for (; i < rdr.FieldCount; i++)
                        {
                            d[rdr.GetName(i)] = rdr.GetValue(i);
                        }

                        for (; i < rdr2.FieldCount; i++)
                        {
                            d[rdr2.GetName(i)] = rdr2.GetValue(i);
                        }

                        list.Add(d);
                    }




                    rdr2.Close();

                    //list.Add(d);
                }
                JavaScriptSerializer j = new JavaScriptSerializer();
                Response.Write(j.Serialize(list.ToArray()));

            }
  • 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-06-05T04:53:44+00:00Added an answer on June 5, 2026 at 4:53 am

    The error message is a bit misleading. Unless you have MultipleActiveResultSets=True in your connection string, you can have only one active result set per connection. This is still the case, if every reader hat it’s own separate SqlCommand object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to use .net's System.IO.Compression.GZipStream to compress and decompress a directory. But I
I wanted to use the currentStateChange event in my application but whatever code being
I wanted to use RavenDB as back-end for my website . but right now
I wanted to use FreeTTS with Drupal 7. Is it possible? Is there any
I wanted to use JET (Java Emitter Templates) in my Netbeans projects, but had
I wanted to use monotouch, but unfortunately I don't have $400 to spend. So
I wanted to use an ExpandableListView for my Fragment but since it's not native,
I recently wanted use regex in Cocoa app. But I found that Cocoa does
I wanted use MVC and renderpartial to generate a menu but but could not
I wanted to use gson in my android project so I followed a tutorial

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.