I am making a multiple choice quiz in vb with the questions and answers stored in an access database. When trying to display the question and answers on my labels, they don't change.

Here is my code:

Imports System.Data.OleDb
Public Class Football_Questions

    Dim con As New OleDbConnection

    Private Sub Football_Questions_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        con.ConnectionString = "provider= microsoft.ACE.OLEDB.12.0; data source= E:\College Work Year 2\Project\questions.accdb"
        con.Open()

        showItems()
    End Sub


    Private Sub showItems()
        Dim ds As New DataSet
        Dim dt As New DataTable
        ds.Tables.Add(dt)
        Dim da As New OleDbDataAdapter

        da = New OleDbDataAdapter("SELECT * FROM [football_questions]", con)
        da.Fill(dt)

        lblQuestion.Text = dt.Rows(0).Item(2)
        lblAnswer1.Text = dt.Rows(0).Item(3)
        lblAnswer2.Text = dt.Rows(0).Item(4)
        lblAnswer3.Text = dt.Rows(0).Item(5)
        lblAnswer4.Text = dt.Rows(0).Item(6)

        con.Close()

    End Sub
End Class

My database has 6 tables and each table has the following fields:

ID
Topic
Question
Answer 1
Answer 2
Answer 3
Answer 4
Correct Answer 

Any help would be much appreciated.

Edited 1 Year Ago by Reverend Jim: Corrected code formatting

There doesn't seem to be a mechanism for changing the question (such as a button). As is, it always loads the first question from the table in the database dt.Rows(0).... To change the question, change '0' to another row number. A basic way to do this is to use two buttons ("Next" and "Previous"). Use a counter variable to keep track of the current question number. Increment this value when the "Next" button is pressed--decrement the value when the "Previous" button is pressed.

What do you want to do when you get to the last question and the user clicks the "Next" button?
What do you want to do when you get to the first question and the user clicks the "Previous" button?

Why do you have 6 tables with the exact same fields?

It doesn't display what is in the database, the labels stay as what was originally set when i created the form. I haven't created next and previous buttons yet because i haven't been able to get this to work first.

This article has been dead for over six months. Start a new discussion instead.