OleDb in VB.net only returns the first column
I don't know where I've gone wrong, stared at it for 2 hours straight and tried 150 different variations. Don't know where the error is that makes it not return any other fields than the first one.
And yes, I know it looks really confusing, I was going to put the 5 readings as a function but I got overwhelmed by the problem
Private Sub StartBtn_Click(sender As Object, e As EventArgs) Handles StartBtn.Click
Dim Numbers As New List(Of Integer)
For X As Integer = 1 To 15
Dim Num As Integer = RandomNum()
Numbers.Add(Num)
Next
Dim temp_QuestionSet As New List(Of Question)
provider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dataFile = "Data Source=C:\course work\dttmq.accdb"
connString = provider & dataFile
Try
Connection.ConnectionString = connString
Connection.Open()
Catch ex As Exception
System.Console.Beep()
MsgBox("Error")
End Try
For Each Number In Numbers
Dim _question As New Question
_question.ID = Number
Using Connection
Dim command As New OleDbCommand("SELECT Question FROM final WHERE QuestionID = " & Number.ToString, Connection)
Try
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
_question.Q = reader(0).ToString()
End While
reader.Close()
Catch ex As Exception
End Try
End Using
Using Connection
Dim command As New OleDbCommand("SELECT (Answer1) FROM final WHERE QuestionID = " & Number.ToString, Connection)
Try
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
_question.A = reader(0).ToString()
End While
reader.Close()
Catch ex As Exception
End Try
End Using
Using Connection
Dim command As New OleDbCommand("SELECT Answer2 FROM final WHERE QuestionID = " & Number.ToString, Connection)
Try
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
_question.B = reader(0).ToString()
End While
reader.Close()
Catch ex As Exception
End Try
End Using
Using Connection
Dim command As New OleDbCommand("SELECT Answer3 FROM final WHERE QuestionID = " & Number.ToString, Connection)
Try
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
_question.C = reader(0).ToString()
End While
reader.Close()
Catch ex As Exception
End Try
End Using
Using Connection
Dim command As New OleDbCommand("SELECT Answer4 FROM final WHERE QuestionID = " & Number.ToString, Connection)
Try
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
_question.D = reader(0).ToString()
End While
reader.Close()
Catch ex As Exception
End Try
End Using
Using Connection
Dim command As New OleDbCommand("SELECT CorrectAnswer FROM final WHERE QuestionID = " & Number.ToString, Connection)
Try
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
_question.Z = reader(0).ToString()
End While
reader.Close()
Catch ex As Exception
End Try
End Using
temp_QuestionSet.Add(_question)
Next
End Sub