Day 28 -资料库应用小程序 会员新增删除(内涵程序码)

废话不多说直接开始

我们点选注册按钮会连结到这个表单
https://ithelp.ithome.com.tw/upload/images/20211012/20141567AZ6kyuAaUD.jpg

首先是注册按钮内的程序码

 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();

再来是进到删除帐号的
https://ithelp.ithome.com.tw/upload/images/20211012/2014156744xVDSlVGO.jpg

会员删除按钮的程序码

 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();

实测

加入一笔资料测试
https://ithelp.ithome.com.tw/upload/images/20211012/201415672EuER8sCPw.jpg

加入成功~
https://ithelp.ithome.com.tw/upload/images/20211012/20141567BIIbihfe6H.jpg

把刚刚那笔删除
https://ithelp.ithome.com.tw/upload/images/20211012/20141567CddN3kaDst.jpg

删除成功~

https://ithelp.ithome.com.tw/upload/images/20211012/201415677LYyoW00Rg.jpg

下篇见~


<<:  什麽是软件工程 (Software Engineering)?我们还需要它吗?

>>:  Day 27 上传自己的 Image 到 Dockerhub

[Day 2] 快来探索AI的世界

快来探索AI的世界 Day 2 学习目标 人工智慧的演进 人工智慧的分级 机器是如何学习的 人工智慧...

.Net Core Web Api_笔记10_路由约束

针对属性路由可以透过Route() 或 Http verbs方式来设置路由模板 在路由模板当中我们还...

[Day 10] 近朱者赤,近墨者黑 - KNN

近朱者赤,近墨者黑 - KNN 今日学习目标 K-近邻演算法介绍 KNN 演算法解析 KNN 於分类...

[Day10] ASI - 自动插入分号

ASI (Automatic Semicolon Insertion) ASI 是 JavaScri...

#3 JavaScript Crash Course 2

今天教 Promise Async / Await。 Promise Promise 这个东西跟时间...