예제 #1
0
        internal List<Question> random()
        {
            List<Question> question_list = new List<Question>();
            string sql = string.Format("SELECT *FROM question AS t1 JOIN(SELECT ROUND(RAND() * ((SELECT MAX(id) FROM question) - (SELECT MIN(id) FROM question)) + (SELECT MIN(id) FROM question)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 5; ");
            DataSet testDataSet = null;
            MySqlConnection conn = new MySqlConnection(connStr_local);
            try
            {
                conn.Open();
                // 创建一个适配器
                MySqlDataAdapter adapter = new MySqlDataAdapter(sql, conn);
                // 创建DataSet,用于存储数据.
                testDataSet = new DataSet();
                // 执行查询,并将数据导入DataSet.
                adapter.Fill(testDataSet, "result_data");
            }
            // 关闭数据库连接.
            catch (Exception e)
            {
                //log4net.ILog log = log4net.LogManager.GetLogger("MyLogger");
                //log.Debug(e.Message);
                conn.Close();
                Console.WriteLine(e.Message);
                return question_list;
                //Console.ReadLine();

            }
            finally
            {
                conn.Close();
            }
            if (testDataSet != null && testDataSet.Tables["result_data"] != null && testDataSet.Tables["result_data"].Rows != null)
            {
                foreach (DataRow testRow in testDataSet.Tables["result_data"].Rows)
                {
                    Question question = new Question();
                    //int id = Convert.ToInt32(testRow["questionID"].ToString());
                    string content = testRow["content"].ToString();
                    question.questionID = testRow["questionID"].ToString();
                    question.content = content;
                    question.questionType = testRow["questionType"].ToString();
                    question.rightAnswer = testRow["rightAnswer"].ToString();
                    question.answerExplain = testRow["answerExplain"].ToString();
                    question.difficulty = testRow["difficulty"].ToString();
                    question_list.Add(question);

                }
            }
            return question_list;
        }
예제 #2
0
        internal List<Question> SelectExp(string sql)
        {
            // List<Question> question_list = new List<Question>();
            List<Question> question_list = new List<Question>();

            DataSet testDataSet = null;
            MySqlConnection conn = new MySqlConnection(connStr_local);
            try
            {
                conn.Open();
                // 创建一个适配器
                MySqlDataAdapter adapter = new MySqlDataAdapter(sql, conn);
                // 创建DataSet,用于存储数据.
                testDataSet = new DataSet();
                // 执行查询,并将数据导入DataSet.
                adapter.Fill(testDataSet, "result_data");
            }
            // 关闭数据库连接.
            catch (Exception e)
            {
                //log4net.ILog log = log4net.LogManager.GetLogger("MyLogger");
                //log.Debug(e.Message);
                conn.Close();
                Console.WriteLine(e.Message);
                return question_list;
                //Console.ReadLine();

            }
            finally
            {
                conn.Close();
            }
            if (testDataSet != null && testDataSet.Tables["result_data"] != null && testDataSet.Tables["result_data"].Rows != null)
            {
                foreach (DataRow testRow in testDataSet.Tables["result_data"].Rows)
                {
                    Question question = new Question();
                    //int id = Convert.ToInt32(testRow["questionID"].ToString());
                    string content = testRow["content"].ToString();
                    question.questionID = testRow["questionID"].ToString();
                    question.content = content;
                    question.answerExplain = testRow["answerExplain"].ToString();
                    question_list.Add(question);

                }
            }
            return question_list;
        }
예제 #3
0
        internal List<Question> getQuestion(string id)
        {
            List<Question> question_list = new List<Question>();
            string sql = string.Format("select * from question where courseSectionID='{0}' and questionType=0 ORDER BY RAND() limit 5", id);
            DataSet testDataSet = null;
            MySqlConnection conn = new MySqlConnection(connStr_local);
            try
            {
                conn.Open();
                // 创建一个适配器
                MySqlDataAdapter adapter = new MySqlDataAdapter(sql, conn);
                // 创建DataSet,用于存储数据.
                testDataSet = new DataSet();
                // 执行查询,并将数据导入DataSet.
                adapter.Fill(testDataSet, "result_data");
            }
            // 关闭数据库连接.
            catch (Exception e)
            {
                //log4net.ILog log = log4net.LogManager.GetLogger("MyLogger");
                //log.Debug(e.Message);
                conn.Close();
                Console.WriteLine(e.Message);
                return question_list;
                //Console.ReadLine();

            }
            finally
            {
                conn.Close();
            }
            if (testDataSet != null && testDataSet.Tables["result_data"] != null && testDataSet.Tables["result_data"].Rows != null)
            {
                foreach (DataRow testRow in testDataSet.Tables["result_data"].Rows)
                {
                    Question question = new Question();
                    string content = testRow["content"].ToString();
                    question.questionID = testRow["questionID"].ToString();
                    question.difficulty = testRow["difficulty"].ToString();
                    question.content = content;
                    question.questionType = testRow["questionType"].ToString();
                    question.rightAnswer = testRow["rightAnswer"].ToString();
                    question.answerExplain = testRow["answerExplain"].ToString();
                    question_list.Add(question);

                }
            }
            return question_list;
        }