Example #1
0
        //删除按钮
        private void delete_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.SelectedCells.Count == 0)
                {
                    MessageBox.Show("请选择要删除的数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    string YGID = dataGridView1.SelectedCells[0].Value.ToString();//学生号或者教师号码

                    string table; string ID_name;
                    if (treeView1.SelectedNode.Text == "所有学生")
                    {
                        table   = "student";
                        ID_name = "stu_id";
                    }
                    else
                    {
                        table   = "teacher";
                        ID_name = "tea_id";
                    }
                    operate.DeleUserInfo(YGID);  //删除相关信息
                    string Delsql = "delete from " + table + " where " + ID_name + "='" + YGID + "'";
                    operate.OperateData(Delsql); //删除(教师表/学生表)信息
                    MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                MessageBox.Show("删除操作失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #2
0
 //删除记录(将选中记录的登录事件重置为'2012/01/01 0:00:00')
 private void delete_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.dataGridView1.SelectedCells.Count == 0)
         {
             MessageBox.Show("请选择要删除的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         else
         {
             string user_name = dataGridView1.SelectedCells[0].Value.ToString(); //得到用户名
             string delUser   = "******" + user_name + "'";
             operate.OperateData(delUser);                                       //删除用户信息
             operate.DeleUserInfo(user_name);
             MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch
     {
         MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }