public void Load_Database_History() { #region DatabaseHistory dbhp = new DatabaseHistory(Students_LoginDetails_LoggedInAs_TextBox.Text, Students_LoginDetails_UserLevel_TextBox.Text); this.Hide(); dbhp.ShowDialog(); #endregion }
public void Delete_DatabaseHistory() { #region try { string sqlQuery1 = $"DELETE FROM dbo.DatabaseHistory WHERE ActionID = {DatabaseHistory_ActionDetails_ActionID_TextBox.Text}"; //DBCC CHECKIDENT() will automically numerically seed each record. This seed will be each record's Primary Key string sqlQuery2 = $"DBCC CHECKIDENT('dbo.DatabaseHistory')"; using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd1 = new SqlCommand(sqlQuery1, conn); DialogResult dialog = MessageBox.Show("Are you sure you want to delete this DatabaseHistory record?:" + $"\n\nActionID:\n{DatabaseHistory_ActionDetails_ActionID_TextBox.Text}\n" + $"\nActionDescription:\n{DatabaseHistory_ActionDetails_ActionDescription_TextBox.Text}\n" + $"\nPerformedByUsername:\n{DatabaseHistory_ActionDetails_PerformedByUsername_TextBox.Text}", "Delete Record", MessageBoxButtons.YesNo ); if (dialog == DialogResult.Yes) { int a = cmd1.ExecuteNonQuery(); if (a > 0) { MessageBox.Show("Record Deleted Successfully", "Successful Delete", MessageBoxButtons.OK); } else { MessageBox.Show("Record Deletion Failed. Please try again", "Failed Delete", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } DatabaseHistory dbhp = new DatabaseHistory(DatabaseHistory_LoginDetails_LoggedInAs_TextBox.Text, DatabaseHistory_LoginDetails_UserLevel_TextBox.Text); this.Hide(); dbhp.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion }