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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:11:32+00:00 2026-06-09T09:11:32+00:00

I have the code below which is intended to build a dictionary object with

  • 0

I have the code below which is intended to build a dictionary object with the following construction Dictionary<string<Dictionary<string, string>. For some reason each time I add an item to it the key text is correct but the value (dictionary) overwrites the previous one. This is probably better explained like this:

Iteration 1

  • key1, dictionary1

Iteration 2

  • key1, dictionary2
  • key2, dictionary2

Iteration 3

  • key1, dictionary3

  • key2, dictionary3

  • key3, dictionary3

What is causing this and how can I fix this code to stop it overwriting the dictionary in each entry?

QueryNameUserQueryString = new Dictionary<string, string>();
DialectDictionary = new Dictionary<string, Dictionary<string, string>>();

while (dataBaseConnection.NextRecord())
                {
                if (QueryNameUserQueryString != null)
                    {
                    QueryNameUserQueryString.Clear();
                    }

                string dialect = dataBaseConnection.GetFieldById (0);

                //If no dialect then carry out next iteration
                if (String.IsNullOrEmpty (dialect))
                    {
                    continue;
                    }

                try
                    {
                    dataBaseConnection2.ExecutePureSqlQuery ("SELECT * FROM " + sqlFactoryTable + " WHERE SQL_FACTORY_DIALECT = '" + dialect + "'");
                    }
                catch
                    {
                    dataBaseConnection.Close();
                    dataBaseConnection2.Close();

                    throw;
                    }

                //Do we have query strings for this dialect?
                if (!dataBaseConnection2.HasRows())
                    {
                    continue;
                    }

                //loop through query strings
                while (dataBaseConnection2.NextRecord())
                    {
                    string queryName = dataBaseConnection2.GetFieldById (2);
                    string queryString = dataBaseConnection2.GetFieldById (3);
                    string user = dataBaseConnection2.GetFieldById (4);

                    //create composite key for dictionary
                    string compositeKey = dialect + "," + queryName + "," + user;

                    if (QueryNameUserQueryString != null)
                        {
                        //Construct our query string dictionary
                        QueryNameUserQueryString.Add (compositeKey, queryString);
                        }
                    }

                //If we have a query string dictionary
                if (QueryNameUserQueryString != null)
                    {
                    //Ensure m_dialect dictionary is not null
                    if (DialectDictionary != null)
                        {
                        //Construct our dictionary entry for this dialect
                        DialectDictionary.Add (dialect, QueryNameUserQueryString);
                        }
                    }
                }
            }
  • 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-09T09:11:33+00:00Added an answer on June 9, 2026 at 9:11 am

    You seem to be using the same instance of QueryNameUserQueryString on every iteration. When it’s added to the DialectDictionary, it’s added as a reference – not a copy of the original.

    To “properly” solve the issue, I would move the declaration of your QueryNameUserQueryString variable inside the while-scope. That way you would make sure that it can only exist in the scope of a single iteration, not across several. When it’s added to the DialectDictionary, the reference lives on in that dictionary and you’re safe to leave the scope.

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

Sidebar

Related Questions

I have the following code below which works, but I want to insert values
I have below code which overrides equals() and hashcode() methods. public boolean equals(Object obj)
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
I have a function(please see code below) which reads some data from the web.
I have this GWT code below which have some slight problem: It's either the
I have the code below which works fine, steps through the rows pinging each
Hello all i have the code below which produces four wheels each with the
I have the code below which I use clone() and live() . The code
I have the code below which I use clone() and delegate() . The code
I have wrote the code below which was taken from Java How to program

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.