Beispiel #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "Delete" && (e.RowIndex >= 0))
            {
                try
                {
                    if (MessageBox.Show("Are You Sure You Want to Delete this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        conn.Open();
                        int        id      = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["GroupId"].Value);
                        string     m       = String.Format("DELETE FROM [Group] Where Id = @Id ");
                        SqlCommand command = new SqlCommand(m, conn);
                        command.Parameters.Add(new SqlParameter("@Id", id));

                        int rows = command.ExecuteNonQuery();
                        if (rows != 0)
                        {
                            MessageBox.Show("Data deleted!");
                            this.Hide();
                            AddStudenttoExistinggrp r = new AddStudenttoExistinggrp();
                            r.Show();
                        }
                        conn.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                conn.Close();
            }
            if (dataGridView1.Columns[e.ColumnIndex].Name == "AssignStudent" && (e.RowIndex >= 0))
            {
                panel1.Show();
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            AddStudenttoExistinggrp h = new AddStudenttoExistinggrp();

            h.Show();
        }