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.