Hi, i have a problem with looping through the data in database. I have two tables namely question and answer table.
In question tables, I had qnsID, StemID, stem(which is the question text), AnsID(took it from answer table).
In answer table, i had AnsID, stemID, option.
I will select one question from the table with options belong to the question. I had tried this to my code.
Public Function getID() As DataSet
Dim ds As New DataSet
Dim da As New SqlDataAdapter("SELECT stemID, stem, AnsID FROM question ", cn)
cn.Open()
da.Fill(ds)
cn.Close()
Return ds
End Function
Public Function selectQA1(ByVal qn As String) As DataSet
Dim ds As New DataSet
Dim da As New SqlDataAdapter("SELECT op FROM ans, question WHERE ans.stemID = question.stemID AND question.AnsID = ans.AnsID ", cn)
cn.Open()
da.Fill(ds)
cn.Close()
Return ds
End Function
These are the two functions that i had created.
And the following are the code behind codes:
Dim counter As Integer = 1
ds = bl.getID()
Dim qn As Integer = ds.Tables(0).Rows(0)("stemID")
Dim qns1 As String = ds.Tables(0).Rows(0)("stem")
Dim anID As Integer = ds.Tables(0).Rows(0)("AnsID")
lb_qns1.Text = qns1
ds = bl.selectQA1(qn)
If counter = anID Then
Dim round As String = ds.Tables(0).Rows(0)("op")
rb_round.Text = round
counter += 1
ElseIf counter = anID Then
counter += 1
Dim heart As String = ds.Tables(0).Rows(0)("op")
rb_heart.Text = heart
ElseIf counter = anID Then
counter += 1
Dim sq As String = ds.Tables(0).Rows(0)("op")
rb_square.Text = sq
End If
The output : only rb_round.Text display the correct option, the rest are blank. Can anyone help me with this problem? Thnk
Regards
tiffany
In question tables, I had qnsID, StemID, stem(which is the question text), AnsID(took it from answer table).
In answer table, i had AnsID, stemID, option.
I will select one question from the table with options belong to the question. I had tried this to my code.
Public Function getID() As DataSet
Dim ds As New DataSet
Dim da As New SqlDataAdapter("SELECT stemID, stem, AnsID FROM question ", cn)
cn.Open()
da.Fill(ds)
cn.Close()
Return ds
End Function
Public Function selectQA1(ByVal qn As String) As DataSet
Dim ds As New DataSet
Dim da As New SqlDataAdapter("SELECT op FROM ans, question WHERE ans.stemID = question.stemID AND question.AnsID = ans.AnsID ", cn)
cn.Open()
da.Fill(ds)
cn.Close()
Return ds
End Function
These are the two functions that i had created.
And the following are the code behind codes:
Dim counter As Integer = 1
ds = bl.getID()
Dim qn As Integer = ds.Tables(0).Rows(0)("stemID")
Dim qns1 As String = ds.Tables(0).Rows(0)("stem")
Dim anID As Integer = ds.Tables(0).Rows(0)("AnsID")
lb_qns1.Text = qns1
ds = bl.selectQA1(qn)
If counter = anID Then
Dim round As String = ds.Tables(0).Rows(0)("op")
rb_round.Text = round
counter += 1
ElseIf counter = anID Then
counter += 1
Dim heart As String = ds.Tables(0).Rows(0)("op")
rb_heart.Text = heart
ElseIf counter = anID Then
counter += 1
Dim sq As String = ds.Tables(0).Rows(0)("op")
rb_square.Text = sq
End If
The output : only rb_round.Text display the correct option, the rest are blank. Can anyone help me with this problem? Thnk
Regards
tiffany