Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a button named "Generate". The function of this button is to move to the next record.


Me.QuestionnairesBindingSource.MoveNext()


I want to move to the next record randomly using the code. Any idea how to that? can anyone modify the code?

Help from a newbie..

Server : how to generate question randomly?
Posted
Updated 9-Sep-13 4:38am
v3
Comments
ShivKrSingh 9-Sep-13 9:27am    
Your Question is not clear. Please provide more details. You can use "order by NewID()" in your query to get question randomly from database.
akosisugar 9-Sep-13 10:34am    
i used service-based database in my application and add it as my datasource. from my datasource tab i click and drag the table questionnaire into the form. thats how i make my application. suppose to be i have already saved questions from the table questionnaire.. in my form i have a button(generate button) to move to the next record from the tablequestionnaire. any idea on how can i move next to another record randomly using the given code?..

Image: https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-frc3/1235878_720592251289535_467913979_n.jpg
OriginalGriff 9-Sep-13 9:31am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
akosisugar 9-Sep-13 10:02am    
im sorry im a newbie in this site..
OriginalGriff 9-Sep-13 10:05am    
It's not just here, it's basic Netiquette:
http://en.wikipedia.org/wiki/Etiquette_(technology)
And it applies pretty much everywhere on the net.

1 solution

First, read all your questions into a List.[^]

Next, use the random number generator to generate a random number between 0 and n, where n is the count of the list items minus 1.

Display that question, and remove it from the list if you don't want it to show up again. Repeat at the second step.

If you gave code or a database schema, I could expand on this with code as well, but since you didn't give anything to work with, all I can give you is the process.
 
Share this answer
 
v2
Comments
akosisugar 9-Sep-13 10:40am    
i used service-based database in my application and add it as my datasource. from my datasource tab i click and drag the table questionnaire into the form. thats how i make my application. suppose to be i have already saved questions from the table questionnaire.. in my form i have a button(generate button) to move to the next record from the tablequestionnaire. any idea on how can i move next to another record randomly using the given code?..

Image: https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-frc3/1235878_720592251289535_467913979_n.jpg
Ron Beyer 9-Sep-13 10:51am    
Just like I said, read them (sequentially) into a List, then pick out a random question from that list. There are no methods for random access to a data source since that's not how database cursors work. You need to read all the data you want, then after you've read it, you can randomize it.
akosisugar 9-Sep-13 11:25am    
uk sir. tnx for your idea. hope i can manage it.

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