private void btnUpdate_Click(object sender, EventArgs e)
        {
            //判断是否选中dataGridView1里的一行
            if (dataGridView1.SelectedRows.Count <= 0)
            {
                MessageBox.Show("请选择一行进行操作");
                return;
            }
            Student newStu = new Student();

            newStu.ID             = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
            newStu.Name           = txtName.Text;
            newStu.Destination    = txtDestination.Text;
            newStu.Departure_date = txtDeparure_date.Text;
            newStu.Return_date    = txtReturn_date.Text;


            //保存修改
            if (stu.UpdateStudent(newStu))
            {
                MessageBox.Show("修改成功");
                dataGridView1.DataSource = stu.GetStudentList();
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }
Exemple #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count <= 0)          //用于判断是否选中了DataGridView中的一行
            {
                MessageBox.Show("请选中一行进行操作");
                return;
            }
            Student newStu = new Student();

            newStu.ID   = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
            newStu.Name = txtName.Text;
            newStu.Age  = int.Parse(txtAge.Text);

            //保存修改
            if (stu.UpdateStudent(newStu))
            {
                MessageBox.Show("修改成功");
                dataGridView1.DataSource = stu.GetStudentList();
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }