private void AddCommentButton_Click(object sender, EventArgs e) { CreateNewOptions input = new CreateNewOptions(); input.getLatestsectionID(); input.addOptionTitle(titleTextBox.Text); input.addOptionComment(commentTextBox.Text); input.writeOptionDetailsToDB(); Close(); CreateTemplateSections reOpen = new CreateTemplateSections(); reOpen.Show(); }
//A method that gets the lastest section ID to act as a foreign key for options table public void getSectioneID(string sqlQuery) { //Create SQL Command object. SqlCommand command = new SqlCommand(); CreateNewOptions getSecID = new CreateNewOptions(); command.CommandType = CommandType.Text; command.CommandText = sqlQuery; //Opens Connection to the Database. openConnection(); command.Connection = connectionToDB; //Executes SQL Query and enters the output into Variable. int ID = Convert.ToInt32(command.ExecuteScalar().ToString()); //calls the method to pass the ID variable to the secID from SectionID. getSecID.turn_to_SecID(ID); //Closes Database Connection closeConnection(); }