从SQL数据库中获取随机问题

问题描述:

先生,

我的数据库就像

Sir,

My database is like

--------------------------------
NO            int
Question      vachar(50)
op1           vachar(20)
op2           vachar(20)
op3           vachar(20)
op4           vachar(20)
Ans           vachar(20)
Subjectcode   varchar(20)
----------------------------------


数据库中包含大量有关各种SubjectCode的问题.

我想从基于subjectCode的数据库中获取一些问题,并从此获取的问题数中,我想在网页上显示随机问题(每页一个问题)

所以我希望你能帮助我...

非常感谢....


Database has large number of questions of various SubjectCode.

I want to fetch some number of question from database based on subjectCode and from this numberof fetched question I want to display random question on to the web-page (one question per page)

So I hope you will help me...

Thanks a lot....

您可以获取表中行的select count(*) from tablename,并使用.net Random类. />
You can get the select count(*) from tablename of the row in the table, and use the .net Random class.
Random r = new Random();
int i = r.Next(countFromTheTable)+1; // zero based add 1


请在使用DetailsView的随机问题(帮助)中找到正确答案 [在线测验 [如何从SQL表 [
Please go through correct answer in Random Questions using DetailsView (Help)[^].

Best Codeproject Articles

1. Online Quiz[^]
2. How to make a random selection from an SQL table[^]