سؤال

How to randomly display 10 question from database? How can i check the answer is correct with database or not?

        db.command(true, "SELECT * FROM question WHERE Age_group='" +category + "'");
        foreach (DataRow item in db.result.Rows)
        {
            question_list.Add (Convert.ToInt32(item["id"]));
        }

        for (int i = 0; i < max_question; i++)
        {
            int index = ran.Next(question_list.Count);
            question_choose.Add(question_list[index]);
            question_list.Remove(question_list[index]);
        }
هل كانت مفيدة؟

المحلول

select top 10 * from table order by newid()

also, see "order by newid()" - how does it work?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top