iT邦幫忙

2021 iThome 鐵人賽

DAY 30
0
自我挑戰組

菜鳥大學生資料庫學習記系列 第 30

Day 30 -資料庫應用小程式 訂單顯示(內涵程式碼)

  • 分享至 

  • xImage
  •  

廢話不多說直接開始

我們點選訂單查詢按鈕會連結到這個表單

https://ithelp.ithome.com.tw/upload/images/20211014/20141567JNjiip3iVg.jpg

全域變數

  static public string signinusername;
        private string dbHost = "localhost"; //"localhost";
        private string dbPort = "3306";
        private string dbUser = "root";
        private string dbPassword = "";
        private string dbName = "db85cc";
        private string sqlStr = "";


        MySqlConnection conn = null;
        MySqlDataAdapter mySqlDataAdapter;
        DataSet ds;
        void getTables()
        {
            string sqlStr = $"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = \'BASE TABLE\' AND TABLE_SCHEMA = \'{dbName}\'";
            MySqlCommand cmd = new MySqlCommand(sqlStr, conn);
            MySqlDataReader rr = cmd.ExecuteReader(); // execute query
            
            rr.Close();
        }



        //This is my connection string i have assigned the database file address path  
        string MyConnection2 = "datasource=127.0.0.0;port=3306;username=root;password=;Allow Zero Datetime=True;";

顯示按鈕:

 
       
            try
            {

                string ss = label2.Text;
                string ss2 = dateTimePicker1.Value.ToShortDateString();
                string Query = "SELECT orderr.Guest_account,detail.Product_name,product.product_price,detail.detail_quantity, product.product_price* detail.detail_quantity,orderr.orderr_date FROM db85cc.orderr ,db85cc.detail,db85cc.product WHERE orderr.Orderr_id = detail.Orderr_id AND detail.Product_name = product.Product_name AND orderr.Guest_account = '" + ss + "'AND orderr.orderr_date = '" + ss2 + "'";
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                MyAdapter.SelectCommand = MyCommand2;
                DataTable dTable = new DataTable();
                MyAdapter.Fill(dTable);
                dgvSelect.DataSource = dTable;                                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

實機展示

我們用1111的帳號登入後查詢他12月15和16日所下的訂單!
https://ithelp.ithome.com.tw/upload/images/20211014/201415674uFBSNhmMJ.jpg

https://ithelp.ithome.com.tw/upload/images/20211014/20141567p9cUvO7Uso.jpg

終於完成30天的挑戰啦~有緣下屆再見喽~~~~~~~~~~


上一篇
Day 29 -資料庫應用小程式 菜單顯示(內涵程式碼)
系列文
菜鳥大學生資料庫學習記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言