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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:44:28+00:00 2026-06-07T08:44:28+00:00

I am implementing a database manager class within my app, mainly because there are

  • 0

I am implementing a database manager class within my app, mainly because there are 3 databases to connect to one being a local one.

However the return function isn’t working, I know the query brings back rows but when it is returned by the class it has 0. What am I missing?

public MySqlDataReader localfetchrows(string query, List<MySqlParameter> dbparams = null)
    {
        using (var conn = connectLocal())
        {
            Console.WriteLine("Connecting local : " + conn.ServerVersion);
            MySqlCommand sql = conn.CreateCommand();
            sql.CommandText = query;
            if (dbparams != null)
            {
                if (dbparams.Count > 0)
                {
                    sql.Parameters.AddRange(dbparams.ToArray());
                }
            }
            MySqlDataReader reader = sql.ExecuteReader();
            Console.WriteLine("Reading data : " + reader.HasRows + reader.FieldCount);
            return reader;
            /*
            using (MySqlCommand sql = conn.CreateCommand())
            {
                sql.CommandText = query;
                if (dbparams != null)
                {
                    if (dbparams.Count > 0)
                    {
                        sql.Parameters.AddRange(dbparams.ToArray());
                    }
                }

                MySqlDataReader reader = sql.ExecuteReader();
                Console.WriteLine("Reading data : " + reader.HasRows + reader.FieldCount);

                sql.Parameters.Clear();
                return reader;
            }*/
        }

    }

And the code to get the results

query = @"SELECT jobtypeid, title FROM jobtypes WHERE active = 'Y' ORDER BY title ASC";
            //parentfrm.jobtypes = db.localfetchrows(query);
            var rows = db.localfetchrows(query);
            Console.WriteLine("Reading data : " + rows.HasRows + rows.FieldCount);
            while (rows.Read()){

            }

These scripts return the following :

Connecting local : 5.5.16
Reading data : True2
Reading data : False0
  • 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-07T08:44:29+00:00Added an answer on June 7, 2026 at 8:44 am

    using (var conn = connectLocal())

    You’re placing the connection inside a using statement, thus closing and disposing the connection after you get to this line:

    return reader;
    

    In other words, when the caller gets the reader back, you’ve closed the database connection and can’t fetch the rows. The connection have to be open while the rows are read.

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

Sidebar

Related Questions

Hi I'm implementing a local database inside of my WP7 app and was wondering
I'm implementing my own Content Provider because I'm gonna synchronize my database with a
I am implementing a search bar from my local database that searches from db
I have a problem with implementing database table library. I have a class Column
I know implementing database is a huge topic, but I want to have a
I am implementing a Database for my (beginner/Android) application. It is not clear to
I am implementing a database application and I will use both JavaDB and MySQL
I am implementing a small database(university Project) and i am facing the following problem.
I have to choose a database for implementing a sharing system. My system will
I'm implementing a service where each user must have his own json/document database. Beyond

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.