private void Create_Click(object sender, EventArgs e) { this.Hide(); Create_Evaluation cr = new Create_Evaluation(); cr.ShowDialog(); this.Close(); }
private void EvaluationData_CellContentClick(object sender, DataGridViewCellEventArgs e) { EvaluationData.Rows[e.RowIndex].ReadOnly = true; int noOfRows = EvaluationData.RowCount; if (e.ColumnIndex == 4 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) { DialogResult dialogResult = MessageBox.Show("Are you sure that you want to delete it?", "Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SqlConnection con = new SqlConnection(conURL); // connection opens // purpose of checker it to find whether user enter all data in correct format or not // if not in correct format then show exception and handle in catch section con.Open(); try { string cmdText = "DELETE FROM Evaluation WHERE Id = @Id"; SqlCommand c = new SqlCommand(cmdText, con); int Idy = Convert.ToInt32(EvaluationData.Rows[e.RowIndex].Cells[0].Value); c.Parameters.Add(new SqlParameter("@Id", Idy)); //execute it int result = c.ExecuteNonQuery(); if (result < 0) { MessageBox.Show("Error"); } // connection closed con.Close(); // update grid after deletion EvaluationData.DataSource = null; EvaluationData.Rows.Clear(); EvaluationData.Columns.Clear(); update(); // show dialog box if added in table of database MessageBox.Show("Successfully Deleted!!"); } catch (Exception) { MessageBox.Show("This evaluation might be marked against some student so first delete that record then delete it here"); } } else if (dialogResult == DialogResult.No) { } } if (e.ColumnIndex == 5 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) { id = Convert.ToInt32(EvaluationData.Rows[e.RowIndex].Cells[0].Value); this.Hide(); Create_Evaluation create = new Create_Evaluation(); create.ShowDialog(); this.Close(); } else { } }