protected void btnDeleteLabe_Click(object sender, EventArgs e) { //Allow the user to back out string messageBoxText = "Are you sure you want to delete this lab?"; string caption = "Lab Technician Warning"; MessageBoxButton button = MessageBoxButton.YesNoCancel; MessageBoxImage icon = MessageBoxImage.Warning; MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon); if (result == MessageBoxResult.Yes) { //Get the lab ID from the dropdown item string room = ddlLab1.SelectedItem.Text; var splitValueLab = room.Split(' '); int labID = Convert.ToInt16(splitValueLab[0]); //Create a new SQL connection SqlConnection conn = new SqlConnection(connectionString); //Create a new SQL command SqlCommand comm = conn.CreateCommand(); //Delete child records DataLookup.DeleteActionsFromLab(labID); DataLookup.DeleteAreaFromLab(labID); //Assign the query to the command comm.CommandText = "DELETE FROM Lab WHERE ID = @labID"; comm.Parameters.AddWithValue("@labID", labID); //Open the connection conn.Open(); //Execute the command int rows = comm.ExecuteNonQuery(); //Close the connection conn.Close(); //Message box for success/fail if (rows > 0) { MessageBox.Show("Lab Deleted."); } else { MessageBox.Show("Error. No Action Taken."); } } if (result == MessageBoxResult.No | result == MessageBoxResult.Cancel) { MessageBox.Show("No Action Taken"); } }