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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:09:28+00:00 2026-06-08T13:09:28+00:00

Okay, my code is currently: public MySqlDataReader CreateQuery(string queryString, string connectionString ) { using

  • 0

Okay, my code is currently:

    public MySqlDataReader CreateQuery(string queryString, string connectionString )
    {

        using (MySqlConnection connection = new MySqlConnection(connectionString))
        {
            using (MySqlCommand command = new MySqlCommand(queryString, connection))
            {
                command.Connection.Open();
                command.ExecuteNonQuery();

                MySqlDataReader reader = command.ExecuteReader();
                return reader;
            }
        }
    }

In another function, I’ve got:

using(MySqlDataReader readers = _connection.CreateQuery(query, connectString))

Currently, in this form, when I return reader into a readers, there is no value. I’ve stepped through, and verified that at the point of the return, reader had the correct information in it. Yet readers has no values. I’m probably missing something completely silly. But any and all help in this will be appreciated. Thanks!

  • 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-08T13:09:30+00:00Added an answer on June 8, 2026 at 1:09 pm

    With the using command, your code is actually going to dispose of the connection and the command before control is returned to the caller. Essentially your connection object and your command object created in the using statements are disposed before the calling code is able to use it so its no longer usable.

    You probably want to do something with the results of the query rather than the reader itself. Perhaps load it into a table? Something like:

    public DataTable CreateQuery(string queryString, string connectionString )
        {
            DataTable results =  new DataTable("Results");
            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                using (MySqlCommand command = new MySqlCommand(queryString, connection))
                {
                    command.Connection.Open();
                    command.ExecuteNonQuery();
    
                    using (MySqlDataReader reader = command.ExecuteReader())
                        results.Load(reader);
                }
            }
           return results;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so i have this code i wrote: class Connection { public static StreamWriter
Okay so, I'm currently running this code to move a bunch of data from
Okay I have updated my code quite a bit. I am getting a new
Okay, so I've got the following code shown below to create a dialog using
Okay so I am currently trying to make checkboxes based on if a string
Okay. I want to have two threads running. Current code: public void foo() {
Okay so my code pretty much works... except if you click submit a second
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
Okay so i have this code: if (isset($_GET['book'])) { $query= SELECT book_id, title, authors.`author`
Okay I have updated my code a little, but I am still not exactly

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.