Esempio n. 1
0
        public void FlagQuestionRecord(Question_Answers qa)
        {
            conn.Open();
            string updateUser = "******" +
                                "AlreadyUsed = 1 " +
                                "WHERE questionID = ?";

            comm = new OleDbCommand(updateUser, conn);

            OleDbParameter QuestionIDParam = new OleDbParameter("questionID", qa.QuestionID);

            comm.Parameters.Add(QuestionIDParam);

            comm.ExecuteNonQuery();
            conn.Close();
        }
Esempio n. 2
0
        public List <Question_Answers> getQuestionsList()
        {
            conn.Open();

            List <Question_Answers> allQuestions = new List <Question_Answers>();

            string selectQuestions = "SELECT * from QUESTIONS where alreadyused = 0 order by QuestionID";

            comm = new OleDbCommand(selectQuestions, conn);

            questionReader = comm.ExecuteReader(CommandBehavior.CloseConnection);

            while (questionReader.Read())
            {
                string id            = questionReader["QuestionID"].ToString();
                string question      = questionReader["Question"].ToString();
                string answer1       = questionReader["Answer1"].ToString();
                string answer2       = questionReader["Answer2"].ToString();
                string answer3       = questionReader["Answer3"].ToString();
                string answer4       = questionReader["Answer4"].ToString();
                string correctAnswer = questionReader["CorrectAnswer"].ToString();

                Question_Answers questionAndAnswers = new Question_Answers(id, question, answer1, answer2,
                                                                           answer3, answer4, correctAnswer);
                allQuestions.Add(questionAndAnswers);
            }

            if (allQuestions.Count == 0)
            {
                string updateUser = "******" +
                                    "AlreadyUsed = 0 ";

                comm = new OleDbCommand(updateUser, conn);

                comm.ExecuteNonQuery();

                selectQuestions = "SELECT * from QUESTIONS where alreadyused = 0 order by QuestionID";

                comm = new OleDbCommand(selectQuestions, conn);

                questionReader = comm.ExecuteReader(CommandBehavior.CloseConnection);

                while (questionReader.Read())
                {
                    string id            = questionReader["QuestionID"].ToString();
                    string question      = questionReader["Question"].ToString();
                    string answer1       = questionReader["Answer1"].ToString();
                    string answer2       = questionReader["Answer2"].ToString();
                    string answer3       = questionReader["Answer3"].ToString();
                    string answer4       = questionReader["Answer4"].ToString();
                    string correctAnswer = questionReader["CorrectAnswer"].ToString();

                    Question_Answers questionAndAnswers = new Question_Answers(id, question, answer1, answer2,
                                                                               answer3, answer4, correctAnswer);
                    allQuestions.Add(questionAndAnswers);
                }
            }

            questionReader.Close();

            return(allQuestions);
        }