Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Sir/Ma'am

i develop a quiz web application.Now here is a working that no two student have the same questions who are sitting near to each other.
sir my code for ques chane is given below in which lbquescnt,lbmaxques are the text field .
Please help me regarding this condition.

ques_change(Me.lbquescnt.Text + 1)

'Ques change
VB
Public Sub ques_change(ByVal quesid As Integer)


        maxques = Val(lbmaxques.Text)


        If quesid >= 1 Then
            ImageButton1.Enabled = True
        Else
            ImageButton1.Enabled = False
        End If


        'if reaches maximum question
        If quesid = maxques Then
            ImageButton2.Enabled = False
        Else
            ImageButton2.Enabled = True

        End If

        get_ques(quesid)
        get_prev_ans(quesid)
    End Sub

'get Question

VB
Public Sub get_ques(ByVal quesid As Integer)
        str = "select * from quizdetails where quiz_id = '" & quizid & "'"
        cmdly.rst1 = New DataTable
        cmdly.rst1 = cmdly.executenonquery(str)

        str = "select * from quizquestion where quiz_id = '" & quizid & "' and ques_id  = '" & quesid & "' order by ques_id"
        cmdly.rst2 = New DataTable
        cmdly.rst2 = cmdly.executenonquery(str)
        If cmdly.rst2.Rows.Count > 0 Then

            lbquescnt.Text = quesid
            lbques.Text = "Q. " & cmdly.rst2.Rows(0).Item("question").ToString

            cmdly.rst3 = New DataTable
            str = "select * from quizoption where quiz_id = '" & quizid & "' and ques_id  = '" & cmdly.rst2.Rows(0).Item("ques_id") & "'"
            cmdly.rst3 = cmdly.executenonquery(str)

            If cmdly.rst3.Rows.Count > 0 Then
                i = cmdly.rst3.Rows.Count
                c = 0
                quizlst.Items.Clear()

                While c < i
                    Dim qlist As New System.Web.UI.WebControls.ListItem
                    qlist.Text = cmdly.rst3.Rows(c).Item("optionVALUE").ToString
                    qlist.Value = cmdly.rst3.Rows(c).Item("option_id").ToString
                    quizlst.Items.Add(qlist)
                    c = c + 1
                End While
            End If
        End If
    End Sub
<pre>
Posted
Updated 5-Jul-13 0:41am
v2

1 solution

Use ORDER BY NEWID() clause::

VB
str = "select * from quizquestion where quiz_id = '" & quizid & " and ques_id  = ( SELECT TOP 1 ques_id FROM quizquestion ORDER BY NEWID() )"


Also refer my answer(solved): Shuffle one column value in sql table?[^]

Refer: NEWID() ::http://msdn.microsoft.com/en-us/library/aa276822(v=sql.80).aspx[^]
 
Share this answer
 
v4
Comments
ankur789 6-Jul-13 1:10am    
but sir i have a problem i fetch the maxcount on the basis of quesid and if newid fetch directly last question then my submit button has been enabled so how can i work
ankur789 6-Jul-13 1:11am    
with all questions
Kuthuparakkal 6-Jul-13 2:05am    
Try now! i have modified answer... It will fetch different question on each time you execute the query...
ankur789 6-Jul-13 2:31am    
sir this query fetch like this if i have 4 question then
1
4
4
3
3
means not a distict flow has been show suppose a student perform a test and after question 2 newid fetch 3 aftre that it again fetch 2 then problem has been find so
Kuthuparakkal 6-Jul-13 2:36am    
Okay.. You may have to fetch all at once and store it somwhere, then iterate over it.. Please my old answer:
http://www.codeproject.com/Questions/563405/Shuffleplusonepluscolumnplusvalueplusinplussqlplus

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