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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:09:47+00:00 2026-06-16T13:09:47+00:00

Hello I am using this code to get the data I need from 5

  • 0

Hello I am using this code to get the data I need from 5 different tables on a MySQL database.

private void goDateBtn_Click(object sender, EventArgs e)
        {
            reportList.Items.Clear();
            var db = new DBConnect();
            MySqlCommand cmd = null;
            MySqlDataReader dr = null;
            double totalsales = 0;
            try
            {
                if (db.OpenConnection() == true)
                {

                    string cmdstr = "SELECT ol.*, o.*, m.* "+
                                    "FROM orderlist ol "+
                                    "INNER JOIN orderdb o ON ol.order_ID = o.order_ID "+
                                    "INNER JOIN menudb m ON ol.menu_ID = m.menu_ID "+
                                    "INNER JOIN recipelist r ON r.menu_ID = m.menu_ID "+
                                    "INNER JOIN "+
                                    "( SELECT stock_ID, SUM(stock_pricePerPiece) menu_cost "+
                                        "FROM stocksdb "+
                                        "GROUP BY stock_ID )"+
                                    "s ON r.stock_ID = s.stock_ID "+
                                    "WHERE o.order_date >= #" + fromDate.Value.Date + "# AND " +
                                        "o.order_date <= #" + toDate.Value.Date + "#";
                    cmd = new MySqlCommand(cmdstr, db.mycon);
                    dr = cmd.ExecuteReader();
                    string[] info = new string[20];
                    while (dr.Read())
                    {
                        info[1] = (dr["order_ID"].ToString());
                        info[2] = (dr["order_date"].ToString());
                        info[3] = (dr["menu_name"].ToString());
                        info[4] = (dr["menu_cost"].ToString());
                        info[5] = (dr["menu_price"].ToString());
                        info[6] = (Convert.ToDouble(info[5]) - Convert.ToDouble(info[4])).ToString("#0.00");
                        this.reportList.Items.Add(new ListViewItem(new string[] { info[1], info[2], info[3], info[4], info[5], info[6] }));

                        totalsales += Convert.ToDouble(info[6]);
                    }
                }
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                db.CloseConnnection();
            }
            totalSalesTxtBox.Text = totalsales.ToString("#0.00");
            MessageBox.Show("SALES REPORT FINISHED!");
        }

I don’t really know what I did wrong especially in the sql string where the last INNER JOIN is supposed to add up all the stock_pricePerPiece from the stocksdb table wherein the stocks are used on the same menu hence having the same menu_ID in the recipedb table.

I am getting the error on dr = cmd.ExecuteReader();

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

    I realized the answer to this question is not easy to explain but it has something to do with the columns I am trying to recreate virtually through the command string. What I did and what solved the problem was to put the specific columns to retrieve in the SELECT query.

    The working code:

     private void goDateBtn_Click(object sender, EventArgs e)
            {
                reportList.Items.Clear();
                var db = new DBConnect();
                MySqlCommand cmd = null;
                MySqlDataReader dr = null;
                double totalsales = 0;
                try
                {
                    if (db.OpenConnection() == true)
                    {
    
                        string cmdstr = "SELECT DISTINCT ol.*, o.order_ID, o.order_date, o.order_status, m.*, mc.menu_cost " +
                                        "FROM  orderlist ol " +
                                            "INNER JOIN orderdb    o ON ol.order_ID = o.order_ID " +
                                            "INNER JOIN menudb     m ON ol.menu_ID  = m.menu_ID " +
                                            "INNER JOIN " +
                                                "(SELECT SUM(s.stock_pricePerPiece * r.recipe_quantity) AS menu_cost, m.menu_ID " +
                                                    "FROM recipelist r " +
                                                        "INNER JOIN stocksdb s ON r.stock_ID = s.stock_ID " +
                                                        "INNER JOIN menudb m ON r.menu_ID= m.menu_ID " +
                                                    "GROUP BY r.menu_ID " +
                                                 ")" +
                                            "mc ON m.menu_ID = mc.menu_ID " +
                                        "WHERE o.order_date >= '" + fromDate.Value.Date.ToString("yyyy-MM-dd") + " 00:00:00" + "' AND " +
                                            "o.order_date <= '" + toDate.Value.Date.ToString("yyyy-MM-dd") + " 23:59:59" + "' AND " +
                                            "o.order_status = 'COMPLETED'";
    
                        if (menuCheckBox.Checked == true)
                        {
                            cmdstr = cmdstr + " AND m.menu_name = '" + menuBox.Text + "'";
                        }
    
                        cmd = new MySqlCommand(cmdstr, db.mycon);
                        dr = cmd.ExecuteReader();
    
                        string[] info = new string[20];
                        while (dr.Read())
                        {
                            info[1] = (dr["order_ID"].ToString());
                            info[2] = (dr["order_date"].ToString());
                            info[3] = (dr["menu_name"].ToString());
                            info[4] = (dr["order_quantity"].ToString());
                            info[5] = Convert.ToDouble(dr["menu_cost"].ToString()).ToString("#0.00");
                            info[6] = Convert.ToDouble(dr["menu_price"].ToString()).ToString("#0.00");
                            info[7] = ((Convert.ToDouble(dr["menu_price"].ToString()) * Convert.ToDouble(info[4])) - (Convert.ToDouble(dr["menu_cost"].ToString()) * Convert.ToDouble(info[4]))).ToString("#0.00");
                            this.reportList.Items.Add(new ListViewItem(new string[] { info[1], info[2], info[3], info[4], info[5], info[6], info[7] }));
    
                            totalsales += Convert.ToDouble(info[7]);
                        }
                    }
                }
                catch (MySqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (dr != null)
                    {
                        dr.Close();
                    }
                    db.CloseConnnection();
                }
                totalSalesTxtBox.Text = totalsales.ToString("#0.00");
                MessageBox.Show("SALES REPORT FINISHED!");
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i am using this Page.ClientScript.RegisterStartupScript() to call a javascript function from vb code
Consider this code: #include <iostream> using namespace std; class hello{ public: void f(){ cout<<f<<endl;
am sending data using this code in vb6 cds.dwData = CLng(RegisterWindowMessage(MyWMCopyData)) cds.cbData = Len(Message)
Hello Im using OLE DB Source for get rows from a dBase IV file
Hello I'm using this star rating widget http://www.fyneworks.com/jquery/star-rating/ to add functionality for users to
Using this tutorial: http://www.c-sharpcorner.com/uploadfile/UrmimalaPal/creating-a-windows-phone-7-application-consuming-data-using-a-wcf-service/ I have created sample/hello world application on the windows phone
Hello i'm using map() jquery to create a new object array DEMO but this
I have this problem when trying to run hello world program using android SDK.
Hello i have the following problem, I record a video using red5 like this:
hello frieds this is how i usually post a variable using Jquery.. $.post(include/save_legatee.inc.php, {

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.