Help in assigning database value to array value

Hello, Code Masters,

Here I am again today going to seek help and guidance from you.

I have here a manually assigned values to arrays 0 - 19
now my question is, how can I assign values to each array coming from the SQL database?

The catch is, it is a different SQL statement (specifically a different where clause) for each array value. For example:

Dim answers(19) As String

answers(0) = RbAnswers1.SelectedValue
answers(1) = RbAnswers2.SelectedValue
answers(2) = RbAnswers3.SelectedValue
answers(3) = RbAnswers4.SelectedValue
answers(4) = RbAnswers5.SelectedValue
answers(5) = RbAnswers6.SelectedValue
answers(6) = RbAnswers7.SelectedValue
answers(7) = RbAnswers8.SelectedValue
answers(8) = RbAnswers9.SelectedValue
answers(9) = RbAnswers10.SelectedValue
answers(10) = RbAnswers11.SelectedValue
answers(11) = RbAnswers12.SelectedValue
answers(12) = RbAnswers13.SelectedValue
answers(13) = RbAnswers14.SelectedValue
answers(14) = RbAnswers15.SelectedValue
answers(15) = RbAnswers16.SelectedValue
answers(16) = RbAnswers17.SelectedValue
answers(17) = RbAnswers18.SelectedValue
answers(18) = RbAnswers19.SelectedValue
answers(19) = RbAnswers20.SelectedValue


(This one below is what I need help with)

Dim CorrectAnswer(19) As String

CorrectAnswer(0) = "A"
CorrectAnswer(1) = "A"
CorrectAnswer(2) = "A"
CorrectAnswer(3) = "A"
CorrectAnswer(4) = "A"
CorrectAnswer(5) = "A"
CorrectAnswer(6) = "A"
CorrectAnswer(7) = "A"
CorrectAnswer(8) = "A"
CorrectAnswer(9) = "A"
CorrectAnswer(10) = "A"
CorrectAnswer(11) = "A"
CorrectAnswer(12) = "A"
CorrectAnswer(13) = "A"
CorrectAnswer(14) = "A"
CorrectAnswer(15) = "A"
CorrectAnswer(16) = "A"
CorrectAnswer(17) = "A"
CorrectAnswer(18) = "A"
CorrectAnswer(19) = "A"

Dim score As Integer = 0

For i As Integer = 0 To answers.Length - 1
If answers(i) = CorrectAnswer(i) Then
score += 1
End If
Next

lbCorrectAnswerCount.Text = score / 20 * 100


What I want to happen is change the manual assignment of array to getting it from the DB:

Dim CorrectAnswer(19) As String

CorrectAnswer(0) = "A"
CorrectAnswer(1) = "A"
CorrectAnswer(2) = "A"
CorrectAnswer(3) = "A"


to :

CorrectAnswer(0) = Select AnswerValue from tbl_ECM_Questionnaire where QuestionID = 1 and CorrectAnswer = 'Y'"
CorrectAnswer(1) = Select AnswerValue from tbl_ECM_Questionnaire where QuestionID = 2 and CorrectAnswer = 'Y'"

CorrectAnswer(2) = Select AnswerValue from tbl_ECM_Questionnaire where QuestionID = 3 and CorrectAnswer = 'Y'"


and so on...

I did try the data table approach however, my poor programming skills hiner me from achieving the result that I want.
Thank you in advance!
Sign In or Register to comment.