-
randomly select quiz questions
Halor..I am currently doing an online quiz with vb.net and sql server 2000. 10 questions will be randomly selected from 30 questions. I random select the questions using query. Now I would like to store 10 of the questions into an array but do not know how to do so. Please help.
This is the code I had written:
Sub Populate()
Dim cnn As SqlConnection = _
New SqlClient.SqlConnection _
("Data Source=(local);" & _
"Integrated Security=SSPI;" & _
"Initial Catalog=EELANE")
Dim cmd As SqlClient.SqlCommand = _
New SqlClient.SqlCommand("SELECT TOP 5 * FROM QUIZ", cnn)
Dim dap As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter
dap.SelectCommand = cmd
cnn.Open()
'Populate the dataset
dap.Fill(das, "QUIZ")
Dim cmd1 As SqlClient.SqlCommand = _
New SqlClient.SqlCommand _
("SELECT quiz_id, answer_id, answer_choice, answer_remark " & _
"FROM QUIZ,ANSWER_QUIZ WHERE QUIZ.quiz_id = ANSWER_QUIZ.quiz_id", _
cnn)
dap.SelectCommand = cmd1
cnn.Open()
'Populate the dataset
dap.Fill(das, "QUIZ_ANSWER")
'Close the connection because a dataset is a disconnected data source
cnn.Close()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Call routine for creating dataset
Populate()
'Bind quiz questions to each panel
Dim Question(10)
Dim Answer1()
Dim Answer2()
Dim Answer3()
Dim Answer4()
Last edited by galgal5814; 03-10-2006 at 03:05 AM.
-
You already have the questions in a dataset; why do you want to copy them to an array? You may simply bind the dataset to controls on the page.
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
erm...because I choose it at random..u mean eventhough i select random i can just bind de dataset to the control of the page without storing in the array? sorry I am very new at this
-
Yes, even though you select random questions, you can bind the dataset to the page. The dataset and the page don't care that you're selecting random questions; they work the same as they would if you were selecting an entire table.
In your code above, it looks like you're selecting the first five questions in the table: SELECT TOP 5 * FROM Quiz. If you want to select 10 questions at random, try this: SELECT TOP 10 * FROM Quiz ORDER BY NewID().
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
ooo thank you so much Phil..
-
Sorry I had 1 more enquiry.
I want to bind each question to different textbox. How can I select the 1st randomly chose questions to be bind with the 1st question to the 1st textbox..2nd question to the second textbox and so on?
Last edited by galgal5814; 03-10-2006 at 11:39 AM.
Similar Threads
-
By Nancy in forum Database
Replies: 2
Last Post: 01-11-2002, 09:38 PM
-
By bigbastard4 in forum Database
Replies: 2
Last Post: 05-16-2001, 06:24 PM
-
By Nirit Touboul in forum Database
Replies: 7
Last Post: 02-25-2001, 11:34 AM
-
By malikmehmood in forum Database
Replies: 0
Last Post: 11-20-2000, 05:12 AM
-
By ranga raghunathan in forum Enterprise
Replies: 0
Last Post: 03-18-2000, 09:59 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|