Greetings fellow vb.net programmers,

Today i really, really need your help i'm having difficulty in display the quiz items in each textbox i'm out of ideas.

What i need to do is. I need to display all the question that is in the database to the textboxes i thought of something like

if sdr.read()=true then
q1(which is label no. 1).text = sdr("question")

but how am i gonna display the next question? any idea guys? i really appriciate your help. Thank you in advance.

Recommended Answers

All 11 Replies

Add your questions table into an datatable, then:

Dim i, j, n as Integer
n = 3 'Anything is okay
i = CInt(Math.Ceiling(Rnd() * n))
j = CInt(Math.Ceiling(Rnd() * n))
If Dt.Rows.Count >= 3*j + i Then 
    TextBox1.Text = Dt.Rows(j + i).Items("Question").ToString.Trim
    TextBox2.Text = Dt.Rows(2*j + i).Items("Question").ToString.Trim
    TextBox3.Text = Dt.Rows(3*j + i).Items("Question").ToString.Trim
End If

It's a simple version. If you have a array of textboxes, then Loop through it together with your table.

It's not working :/.. this is my current code.

Conn = getConnect()
        sqlCmd = Conn.CreateCommand
        sqlCmd.CommandText = "SELECT question FROM questionnaires"
        dataadapter.SelectCommand = sqlCmd
        dataadapter.Fill(dSet, "questionnaires")
        dTable = dSet.Tables("questionnaires")
        Dim i, j, n As Integer
        n = 2 'Anything is okay
        i = CInt(Math.Ceiling(Rnd() * n))
        j = CInt(Math.Ceiling(Rnd() * n))
        If dTable.Rows.Count >= 2 * j + i Then
            q1.Text = dTable.Rows(j + i).Item("question").ToString.Trim
            q2.Text = dTable.Rows(2 * j + i).Item("question").ToString.Trim

        End If

I fixed it now, try this:

    Public Function GetRandom(ByVal Min As Integer, ByVal Max As Integer) As Integer
        Dim Generator As System.Random = New System.Random()
        Return Generator.Next(Min, Max)
    End Function

    Conn = getConnect()
    sqlCmd = Conn.CreateCommand
    sqlCmd.CommandText = "SELECT question FROM questionnaires"
    dataadapter.SelectCommand = sqlCmd
    dataadapter.Fill(dSet, "questionnaires")
    dTable = dSet.Tables("questionnaires")
    Dim i, j, n As Integer
    n = 2 'Anything is okay
    i = GetRandom(0, n)
    j = GetRandom(0, n)
    If dTable.Rows.Count >= 2 * j + i Then
    q1.Text = dTable.Rows(j + i).Item("question").ToString.Trim
    q2.Text = dTable.Rows(2 * j + i).Item("question").ToString.Trim
    End If

these are the pictures.

the first one is the database and the second one is the quiz form.

Any idea guys :/?

Can you be a little clearer on how you want to present the questions and what you are having difficulty with? Is it the presentation of the questions? Is it the sequencing? Is it the database interface?

I want to show the questions from the questionnaire database to the question label from the quiz form

is not a very clear description.

Sorry sir, i'm having difficulty in presentation of the question column from the database to the form.

Still not clear. How do you want to present the question? For example, do you want to have a form which displays the current question and presents the user with

  • a textbox for entering the answer
  • radio buttons for single multiple-choice response

If the former, will you have a button to submit the answer? If the latter, will selecting a radio button cause the "check my answer" code to run? Will you have a NEXT button so the user can proceed to the next question? Are the questions timed so that the user must respond within a given number of seconds?

If you can't be bothered to clearly state what you want then you can't expect a useful answer.

I'm having difficulty in showing all the items on the database named questionnaire table to the questionlabel in the quiz form.

it should be like this.

When the quiz form loads the question label on the quiz form should load the question column on the questionnaire table.

question1.text must display the question qId1 in the questionnaire table. and
question2.text must display the question qId2 in the questionnaire table

the questions are all displayed in one form and it's a multiple choice type question a radiobutton type.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.