廢話不多說直接開始
我們點選註冊按鈕會連結到這個表單
首先是註冊按鈕內的程式碼
string sqlStr = $"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE=\'BASE TABLE\'AND TABLE_SCHEMA = \'{dbName}\'";
MySqlConnection conn = DBconnection.connectMariaDB(dbUser, dbPassword, dbName);
string Account = tbxCreateID.Text; //帳號
string Password = tbxCreatePassword.Text; //密碼
string Name = tbxName.Text; //名子
string Phone = tbxTelephone.Text; //電話
string Address = tbxPlace.Text; //地址
string Mail = tbxMail.Text; //信箱
string SQL = "INSERT INTO `guest` (`Guest_account`, `guest_password`, `guest_name`, `guest_phone`, `guest_address`, `guest_mail`) VALUES ('" + Account + "','" + Password + "', '" + Name + "','" + Phone + "', '" + Address + "', '" + Mail + "')";
MySqlCommand cmd = new MySqlCommand(SQL, conn); //mysql指令
MySqlDataAdapter adp = new MySqlDataAdapter(cmd); //data偵測
if (string.IsNullOrEmpty(tbxCreateID.Text))
{
MessageBox.Show("請輸入註冊帳號");
return;
}
else if (string.IsNullOrEmpty(tbxCreatePassword.Text))
{
MessageBox.Show("請輸入註冊密碼");
return;
}
else if (string.IsNullOrEmpty(tbxName.Text))
{
MessageBox.Show("請輸入名字");
return;
}
else if (string.IsNullOrEmpty(tbxTelephone.Text))
{
MessageBox.Show("請輸入電話號碼");
return;
}
else if (string.IsNullOrEmpty(tbxPlace.Text))
{
MessageBox.Show("請輸入地址");
return;
}
else if (string.IsNullOrEmpty(tbxMail.Text))
{
MessageBox.Show("請輸入信箱");
return;
}
else
{
cmd.ExecuteNonQuery();
MessageBox.Show("注册成功");
//signin.Close();
this.Close();
}
上一頁的程式碼
this.Close();
離開按鈕的程式碼
Application.Exit();
再來是進到刪除帳號的
會員刪除按鈕的程式碼
if (tbxIDDelete.Text.Trim().Length >= 4)
{
try
{
string MyConnection2 = "datasource=127.0.0.1;port=3306;username=root;password=";
string Query = "delete from db85cc.guest where Guest_account='" + this.tbxIDDelete.Text + "' and guest_password='" + this.tbxPWDelete.Text + "';";
MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
MySqlDataReader MyReader2;
MyConn2.Open();
MyReader2 = MyCommand2.ExecuteReader();
MessageBox.Show("Data Deleted");
while (MyReader2.Read())
{
}
MyConn2.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else { MessageBox.Show("帳號長度不可少於四個字"); }
this.Close();
加入一筆資料測試
加入成功~
把剛剛那筆刪除
刪除成功~
下篇見~