コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
            {
                MessageBox.Show("输入能为空", "提示");
                return;
            }
            if (textBox3.Text != "1" && textBox3.Text != "2" && textBox3.Text != "3")
            {
                MessageBox.Show("权限等级只能为(1,2,3)", "提示");
                return;
            }

            DBcon  DB  = new DBcon();
            string str = "insert into Table_users values ('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "')";

            try
            {
                DBcon.GetCon();
                DB.ExecuteUpdate(str);
                MessageBox.Show("添加成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
            }
            finally
            {
                DB.Con_Close();
            }
        }
コード例 #2
0
ファイル: Form4.cs プロジェクト: lionoa/StudentManager
        private void button2_Click(object sender, EventArgs e)
        {
            DBcon con = new DBcon();

            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("请先输入要添加的信息!");
                return;
            }

            try
            {
                string str = "insert into Students values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "')";

                DBcon.GetCon();
                DBcon DB = new DBcon();
                DB.ExecuteUpdate(str);
                MessageBox.Show("插入成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示");
            }
            finally
            {
                con.Con_Close();
            }
        }