/// <summary> /// Save edit data into Database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (cboName.Text != "" && cboRubricId.Text != "" && txtTotalMarks.Text != "") { RubricId(); AddAssComp(); frmAssessComponent a1 = new frmAssessComponent(); a1.Show(); this.Hide(); } }
private void dgvAssessment_CellContentClick(object sender, DataGridViewCellEventArgs e) { int index = e.RowIndex; DataGridViewRow selected_row = dgvAssessment.Rows[index]; string id = selected_row.Cells[0].Value.ToString(); Int32.TryParse(id, out MyClass.assess); if (e.ColumnIndex == 5) { if (DialogResult.Yes == MessageBox.Show("Do you want to edit the row?", "", MessageBoxButtons.YesNo)) { frmEditAssess c1 = new frmEditAssess(); c1.Show(); this.Hide(); } } else if (e.ColumnIndex == 6) { if (DialogResult.Yes == MessageBox.Show("Do you want to delete the row?", "", MessageBoxButtons.YesNo)) { String conURL1 = "Data Source = DESKTOP-RPO4Q5R\\PARVEEN; Initial Catalog =ProjectB; User ID = mohsin; Password = mohsin123; MultipleActiveResultSets = True"; //String conURL = "Data Source = (local); Initial Catalog = MedicalEncyclopedia; Integrated Security = True; MultipleActiveResultSets = True"; SqlConnection conn1 = new SqlConnection(conURL1); conn1.Open(); //// String asscompId = "SELECT Id FROM AssessmentComponent Where AssessmentId = " + MyClass.assess; SqlCommand sqlCmd = new SqlCommand(asscompId, conn1); SqlDataReader myReader; myReader = sqlCmd.ExecuteReader(); if (!myReader.Read()) { int i = 0; } else { try { MyClass.AssCompid = Convert.ToInt32(myReader.GetValue(0).ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } /// To delete Assessment First Of all delete It from All /// Entities where it is used as Foreign Key String stdres = "Delete FROM StudentResult Where AssessmentComponentId = " + MyClass.AssCompid; SqlDataAdapter sqlDatadapt = new SqlDataAdapter(stdres, conn1); sqlDatadapt.SelectCommand.ExecuteNonQuery(); String asscom = "Delete FROM AssessmentComponent Where AssessmentId = " + MyClass.assess; SqlDataAdapter sqlDataadapt = new SqlDataAdapter(asscom, conn1); sqlDataadapt.SelectCommand.ExecuteNonQuery(); String cmd1 = "Delete FROM Assessment Where Id = " + MyClass.assess; SqlDataAdapter cmd = new SqlDataAdapter(cmd1, conn1); cmd.SelectCommand.ExecuteNonQuery(); conn1.Close(); MessageBox.Show("Data Has been successfuly deleted"); } } else if (e.ColumnIndex == 7) { frmAssessComponent AssessCmp = new frmAssessComponent(); AssessCmp.Show(); this.Hide(); } }