Пример #1
0
        /// <summary>
        /// Displays a warning.
        /// Deletes the selected record from the Student table.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            StudentHelper.currentId = int.Parse(dgvStudents.CurrentRow.Cells["StudentId"].Value.ToString());
            DialogResult result = MessageBox.Show("Are you sure you want to delete the record for: " + StudentHelper.currentId + " " + dgvStudents.CurrentRow.Cells["FirstName"].Value.ToString() + " , " + dgvStudents.CurrentRow.Cells["LastName"].Value.ToString() + "?", "Delete Record", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result == DialogResult.OK)
            {
                if (StudentHelper.DeleteRecord() > 0)
                {
                    StudentHelper.LoadStudents(dgvStudents);
                }
            }
        }
        public ActionResult Delete(int id)
        {
            //String conString = "Data Source=OSC_HR_Mahfuzur;Initial Catalog=Student;Integrated Security=True";
            //SqlConnection con = new SqlConnection(conString);
            //String query = "DELETE from StudentInfo WHERE Id = @id";
            //SqlCommand cmd = new SqlCommand(query, con);
            //cmd.Parameters.AddWithValue("@id",id);

            //con.Open();
            //SqlDataReader rdr = cmd.ExecuteReader();
            repo.DeleteRecord(id);

            return(RedirectToAction("Index"));
        }