Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1958522
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T08:20:22+00:00 2026-05-17T08:20:22+00:00

Greetings everyone, i would just like to ask how do i retrieve data rows

  • 0

Greetings everyone, i would just like to ask how do i retrieve data rows in my table in my database randomly… i was able to create an online quiz wherein it displays the question,choices in consecutive order but what i want is, every time when user will start a quiz it will show questions in random order. I am using mssql 2005 as my database below is my code.. any advice or suggestions is highly sought.. thank you and have a great day..

QuizPage.aspx

<asp:DetailsView ID="questionDetails" runat="server" AutoGenerateRows="False" 
                CellPadding="4" ForeColor="#333333" 
                GridLines="None" Height="50px" Width="550px">
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                <RowStyle BackColor="#F7F6F3" CssClass="generaltext" ForeColor="#333333" />
                <FieldHeaderStyle BackColor="#E9ECF1" CssClass="boldtext" Font-Bold="True" 
                    Width="80px" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <Fields>
                    <asp:TemplateField HeaderText="Question ID">           
                        <ItemTemplate>
                                       <asp:Label ID="question_id" runat="server" Text='<%# Bind("question_id") %>'></asp:Label>
                        </ItemTemplate>                                                                             
                        </asp:TemplateField> 
                         <asp:TemplateField HeaderText="Question:">           
                        <ItemTemplate>
                                       <asp:Label ID="quiz_question" runat="server" Text='<%# Bind("quiz_question") %>'></asp:Label>
                        </ItemTemplate>                                                                             
                        </asp:TemplateField> 
                         <asp:TemplateField HeaderText="Choice 1:">           
                        <ItemTemplate>
                                       <asp:Label ID="choice1" runat="server" Text='<%# Bind("choice1") %>'></asp:Label>
                        </ItemTemplate>                                                                             
                        </asp:TemplateField> 
                         <asp:TemplateField HeaderText="Choice 2:">           
                        <ItemTemplate>
                                       <asp:Label ID="choice2" runat="server" Text='<%# Bind("choice2") %>'></asp:Label>
                        </ItemTemplate>                                                                             
                        </asp:TemplateField> 
                         <asp:TemplateField HeaderText="Choice 3:">           
                        <ItemTemplate>
                                       <asp:Label ID="choice3" runat="server" Text='<%# Bind("choice3") %>'></asp:Label>
                        </ItemTemplate>                                                                             
                        </asp:TemplateField> 
                         <asp:TemplateField HeaderText="Choice 4:">           
                        <ItemTemplate>
                                       <asp:Label ID="choice4" runat="server" Text='<%# Bind("choice4") %>'></asp:Label>
                        </ItemTemplate>                                                                             
                        </asp:TemplateField>
                </Fields>
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" CssClass="generaltext" 
                    ForeColor="#284775" />
            </asp:DetailsView>

    Your Answer:&nbsp;
            <asp:DropDownList ID="answerDropDownList" runat="server" 
                style="margin-bottom: 0px">
                <asp:ListItem Value="1">Answer 1</asp:ListItem>
                <asp:ListItem Value="2">Answer 2</asp:ListItem>
                <asp:ListItem Value="3">Answer 3</asp:ListItem>
                <asp:ListItem Value="4">Answer 4</asp:ListItem>
            </asp:DropDownList>

  <asp:Button ID="buttonNext" runat="server" Text="Next" />

QuizPage.aspx.vb

Private Function CreateConnection() As SqlConnection
    Dim _connectionString As String = ConfigurationManager.ConnectionStrings("LMSConnectionString").ConnectionString
    Return New SqlConnection(_connectionString)
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        getQuestions()
    End If
End Sub
Private Sub getQuestions()
    Dim quiz_id As Integer
    quiz_id = Session("quiz_id")
    Dim connection As SqlConnection = CreateConnection()
    Dim command As SqlCommand = Nothing
    Dim dt As DataTable = New DataTable()
    command = New SqlCommand("SELECT question_id,quiz_question, choice1, choice2, choice3, choice4, answer, quiz_id FROM tblQuizQuestion WHERE (quiz_id = @quiz_id)", connection)
    command.Parameters.AddWithValue("@quiz_id", quiz_id)
    Dim ad As SqlDataAdapter = New SqlDataAdapter(command)
    ad.Fill(dt)
    questionDetails.DataSource = dt
    questionDetails.DataBind()
End Sub
Protected Sub buttonNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonNext.Click

    Try

        ' Save off previous answers
        Dim dr As System.Data.DataRowView
        dr = CType(questionDetails.DataItem, System.Data.DataRowView)

        ' Create Answer object to save values
        Dim a As Answer = New Answer()
        ' a.QuestionID = dr("QuestionOrder").ToString()
        a.CorrectAnswer = dr("answer").ToString()
        a.UserAnswer = answerDropDownList.SelectedValue.ToString()

        Dim al As ArrayList
        al = CType(Session("AnswerList"), ArrayList)
        al.Add(a)

        Session.Add("AnswerList", al)

    Catch ex As Exception


        Response.Redirect("default.aspx")
    End Try

    If questionDetails.PageIndex = questionDetails.PageCount - 1 Then
        ' Go to evaluate answers
        Response.Redirect("results.aspx")
    Else
        questionDetails.PageIndex += 1

    End If

    If questionDetails.PageIndex = questionDetails.PageCount - 1 Then
        buttonNext.Text = "Finished"
    End If
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T08:20:22+00:00Added an answer on May 17, 2026 at 8:20 am

    While searching for a solution for your problem, I stumbled across this post:

    http://haacked.com/archive/2004/06/21/658.aspx

    By using ORDER BY NEWID() in the Select SQL statement you can randomize the result every single time you retrieve the records. I tried it on SQL Server 2008 and works brilliantly for more than 100 records. So all you need to do is modify your Select SQL to:

    SELECT question_id,quiz_question, choice1, choice2, choice3, choice4, answer, quiz_id FROM tblQuizQuestion WHERE (quiz_id = @quiz_id) ORDER BY NEWID()
    

    The other alternative is to create a RandomizeDataTable function that will randomize the order of rows. If the above solution does not work for you then we can take a look at that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings everyone, i just wanna ask.. how do i disable the right click property
Greetings everyone: I would love to get some information from a huge collection of
Greetings Everyone. I was wondering how would I go about drawing an ached line
Greetings, I would like to use EF4 but I only have Visual studio 2010
Greetings Everyone I am using the following code to send data to update to
Greetings everyone and thank you for checking out my post. I am trying to
Greetings everyone! I programmed GUI Application using Java Swing under Windows. Under windows everything
Greetings Overflowers, Is there an SQL DBMS that allows me to create an indexed
Greetings Everyone. I'm currently writing a multi-language programe in C, C++ and fortran on
Greetings everyone! Question : does any one have a success with combining Microsoft Visual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.