Esempio n. 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();
            }
        }
Esempio n. 2
0
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                //打开数据库并创建实例
                DBcon.GetCon();
                DBcon db = new DBcon();

                //选中项的列名
                string strcolumn = dataGridView1.Columns[this.dataGridView1.CurrentCell.ColumnIndex].HeaderText;
                //选中项所在行的学号
                string strrow = Convert.ToString(dataGridView1.CurrentRow.Cells[0].Value);
                //选中的值
                string value = dataGridView1.SelectedCells[0].Value.ToString();
                //更新语句
                string strcom = "update Students set " + strcolumn + "='" + value + "' where 学号 = " + strrow;


                //更新操作
                db.ExecuteUpdate(strcom);
                MessageBox.Show("修改成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
            }
            finally
            {
                DBcon.sql_con.Close();
            }
        }
Esempio n. 3
0
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                //判断是否有信息可以删除
                if (dataGridView1.SelectedRows.Count == 0)
                {
                    MessageBox.Show("未选中或无可删除信息!");
                    return;
                }

                //删除选中的行
                if (MessageBox.Show("确定删除选中的行?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    string str = "delete Table_users where id = '" + dataGridView1.SelectedRows[0].Cells["id"].Value + "'";
                    DBcon  db  = new DBcon();
                    DBcon.GetCon();
                    db.ExecuteUpdate(str);
                    MessageBox.Show("删除成功!");
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
            }
        }
Esempio n. 4
0
        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();
            }
        }
Esempio n. 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            DBcon   Db  = new DBcon();
            string  str = "select * from Table_users";
            DataSet ds  = Db.GetDataSet(str, "Table_users");

            this.dataGridView1.DataSource = ds.Tables["Table_users"].DefaultView;
        }
Esempio n. 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            string  str = "select * from Students";
            DBcon   con = new DBcon();
            DataSet ds  = con.GetDataSet(str, "Students");

            this.dataGridView1.DataSource = ds.Tables["Students"].DefaultView;
        }
Esempio n. 7
0
        private void button6_Click(object sender, EventArgs e)
        {
            string str1 = comboBox1.Text.ToString();
            string str2 = textBox8.Text.ToString().Trim();

            if (str1 == "" || str2 == "")
            {
                MessageBox.Show("输入不能为空!");
                return;
            }

            string  str = "select * from Students where " + str1 + "='" + str2 + "'";
            DBcon   con = new DBcon();
            DataSet ds  = con.GetDataSet(str, "Students");

            this.dataGridView1.DataSource = ds.Tables["Students"].DefaultView;
        }
Esempio n. 8
0
        private void button3_Click(object sender, EventArgs e)
        {
            //判断是否有信息可以删除
            if (dataGridView1.SelectedRows.Count == 0)
            {
                MessageBox.Show("没有可删除信息!");
                return;
            }

            //删除选中的行
            if (MessageBox.Show("确定删除选中的行?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                string str = "delete Students where 学号 = '" + dataGridView1.SelectedRows[0].Cells["学号"].Value + "'";
                DBcon  db  = new DBcon();
                DBcon.GetCon();
                db.ExecuteUpdate(str);
                MessageBox.Show("删除成功!");
            }
            else
            {
                return;
            }
        }