Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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)
----------------------------------

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....
Posted
Updated 21-Sep-12 7:35am
v3
Comments
Sandeep Mewara 21-Sep-12 13:30pm    
And what is the issue? Did you try anything? Where are you stuck?

You can get the select count(*) from tablename of the row in the table, and use the .net Random class.
C#
Random r = new Random();
int i = r.Next(countFromTheTable)+1; // zero based add 1
 
Share this answer
 
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[^]
 
Share this answer
 
Comments
Please don't forget to mark this as accepted answer, if it has helped you in any way, so that it will be helpful for others to know the solution easily... You will also be awarded with points for accepting... :) :)

Thanks a lot...
Regards,
Tadit

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900