I'm going to develop a project in asp.net with C#. The project is an online examination system. The problem is, how will I select the random question in a certain time period from a database? The database I'm usin开发者_开发问答g is SQL Server 2005. Please give all solutions in C#.
Taking a shot in the dark here
Assuming you have a table with questions, each (hopefully) with an "id" column:
You could go:
1.) Get the total number of questions
2.) Randomly pick the id of a question to be selected from the database
Something like
public Question GetRandomQuestion()
{
Random r = new Random();
int totalNoOfQuestions = GetTotalNoOfQuestions(); //get this from database
int questionIdToPick = r.Next(totalNoOfQuestions);
return GetQuestion(questionIdToPick); //some method to fetch from database
}
精彩评论