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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:50:03+00:00 2026-06-03T19:50:03+00:00

I have an application using the MySQL .Net connection but for some reason i’m

  • 0

I have an application using the MySQL .Net connection but for some reason i’m having a problem parsing the results to return them,

public NameValueCollection[] query(string query)
{
    connect();
    NameValueCollection[] resultSet;

    MySqlCommand command = connection.CreateCommand();
    MySqlDataReader Reader;

    command.CommandText = query;
    connection.Open();
    Reader = command.ExecuteReader();
    string theserows = "";
    while (Reader.Read())
    {
        for (int i = 0; i < Reader.FieldCount; i++){
            theserows += Reader.GetName(i)+"="+Reader.GetValue(i).ToString() + ",";
            Count = i;
        }
        theserows += "\n";
    }
    connection.Close();
    string[] results = theserows.Split(new char[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
    int countResultRows = 0;
    resultSet = new NameValueCollection[Count];
    foreach (string s in results)
    {
        resultSet[countResultRows] = new NameValueCollection();
        string[] result = s.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
        foreach (string col in results)
        {
            if (string.IsNullOrEmpty(col))
                continue;

            string[] kv = col.Split('=');
            resultSet[countResultRows].Add(kv[0], kv[1]);
        }
        countResultRows++;
    }
    return resultSet;
}

In this theserows = "site_id=1,\n" but i have an exception thown on the string[] result = s.Split(','); with the exception IndexOutOfRangeException

Could any one give any insight into why this error would be occurring?

On another note the reason i’m reading it all then building the NameValueCollection is I want to add a logging system that logs the full query and it’s results

EDIT::

“count”(lowercase) changed to countResultRows

CallStack

HTML5Streamer.exe!HTML5Streamer.Classes.MySQL.query(string query) Line 53   C#
HTML5Streamer.exe!HTML5Streamer.Classes.Query.getSiteId(string domain) Line 17 + 0x10 bytes C#
HTML5Streamer.exe!HTML5Streamer.Classes.Query.checkUserPass(string username, string password, string domain) Line 31 + 0xb bytes    C#
HTML5Streamer.exe!HTML5Streamer.Classes.Service.ProccessAdminRequest(System.Net.HttpListenerContext context) Line 239 + 0xd9 bytes  C#
HTML5Streamer.exe!HTML5Streamer.Classes.Service.ProcessRequest(System.Net.HttpListenerContext context) Line 176 + 0xb bytes C#
HTML5Streamer.exe!HTML5Streamer.Classes.Service.ListenerCallback(System.IAsyncResult result) Line 150 + 0xb bytes   C#

Full Exception Detiails

https://i.stack.imgur.com/EST4w.png
Line 52 is resultSet[countResultRows] = new NameValueCollection();
function starts at line 26 ends at 65

  • 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-03T19:50:09+00:00Added an answer on June 3, 2026 at 7:50 pm

    You shouldn’t use same variable names for 2 different values (count, Count), even if it is syntactically correct, this can be confusing.

    Second, you should check if kv length is > 1 before accessing the array

    resultSet[count].Add(kv[0], kv[1]);
    

    If I follow the logic of you program, given the string “site_id=1,\n”, after the split,
    result = {“site_id=1″,”\n”}, for the second string kv = {“\n”} and therefor kv[1] will return an OutOfRangeException.

    Here’s how I would’ve written your code

    string[] results = theserows.Split(new char[]{'\n'},StringSplitOptions.RemoveEmptyEntries);
    resultSet = new NameValueCollection[Count];
    for(int i = 0; i < results.Length && i < Count; i++)
    {
        string s = results[i];
        resultSet[i] = new NameValueCollection();
        string[] result = s.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries);
        foreach (string col in result) // As pointed by other users, this should be result insead of results, again bad var name choice
        {
            string[] kv = col.Split('=');
            if(kv.Length >= 2)
            resultSet[i].Add(kv[0], kv[1]);
        }
     }
    

    Avoiding any possible OutOfRangeExceptions

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

Sidebar

Related Questions

I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it
I have a winforms application connected to Mysql using the .Net driver. I written
I have a c# .net 3.5 application using NHibernate and MySQL. My SQL tables
I have been working on on an AJAX chat application using php, mysql. It's
I'm using: Hibernate MySQL jBoss I have to create an application that allows user
I have a Visual Studio 2008 C# .NET 3.5 project using MySql 5.1.53 and
I have written a simple test application using asp.net mvc with C#. The application
I'm using the MySQL .Net libraries in an older C# application I'm rewriting. The
I have a C# application, using ADO.Net to connect to MSSQL I need to
I'm currently working on a legacy ASP.NET 2.0 web application using a MySQL 5

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.