廢話不多說直接開始
我們點選訂單查詢按鈕會連結到這個表單
全域變數
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日所下的訂單!
終於完成30天的挑戰啦~有緣下屆再見喽~~~~~~~~~~