The following is my code, I am doing project on online examination.when i click on next button the questions are repeated
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Try
Dim daQuestions As New SqlDataAdapter("SELECT TOP 20 * FROM tblQuestions ORDER BY NEWID()", con)
Dim dsQuestions As New Data.DataSet
Dim dtQuestions As New Data.DataTable
If Not con.State = Data.ConnectionState.Open Then con.Open()
daQuestions.Fill(dsQuestions)
dtQuestions = dsQuestions.Tables(0)
If Not dtQuestions.Rows.Count <= 0 Then
If Not IsDBNull(dtQuestions.Rows(0).Item("Question")) Then
lblQuestion1.Text = dtQuestions.Rows(0).Item("Question")
End If
If Not IsDBNull(dtQuestions.Rows(0).Item("Option1")) Then
rblQuestion1.Items(0).Text = dtQuestions.Rows(0).Item("Option1")
End If
If Not IsDBNull(dtQuestions.Rows(0).Item("Option2")) Then
rblQuestion1.Items(1).Text = dtQuestions.Rows(0).Item("Option2")
End If
If Not IsDBNull(dtQuestions.Rows(0).Item("Option3")) Then
rblQuestion1.Items(2).Text = dtQuestions.Rows(0).Item("Option3")
End If
If Not IsDBNull(dtQuestions.Rows(0).Item("Option4")) Then
rblQuestion1.Items(3).Text = dtQuestions.Rows(0).Item("Option4")
End If
End If
Catch ex As Exception
End Try
cmd = New SqlCommand("insert into tblQuestions (Question, Option1, Option2, Option3, Option4,) values (@question, @option1, @option2, @option3, @option4)", con)
cmd.Parameters.AddWithValue("@question", lblQuestion1.Text)
cmd.Parameters.AddWithValue("@option1", rblQuestion1.Text)
cmd.Parameters.AddWithValue("@option2", rblQuestion1.Text)
cmd.Parameters.AddWithValue("@option3", rblQuestion1.Text)
cmd.Parameters.AddWithValue("@option4", rblQuestion1.Text)
Try
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox(" ")
rblQuestion1.Text = ""
rblQuestion1.Text = ""
rblQuestion1.Text = ""
rblQuestion1.Text = ""
Catch ex As Exception
End Try
End If
End Sub
Protected Sub rblQuestion1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblQuestion1.SelectedIndexChanged
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If IsPostBack Then
Try
Dim daQuestions As New SqlDataAdapter("SELECT TOP 20 * FROM tblQuestions ORDER BY NEWID()", con)
Dim dsQuestions As New Data.DataSet
Dim dtQuestions As New Data.DataTable
rblQuestion1.ClearSelection()
If Not con.State = Data.ConnectionState.Open Then con.Open()
daQuestions.Fill(dsQuestions)
dtQuestions = dsQuestions.Tables(0)
If Not dtQuestions.Rows.Count <= 0 Then
If Not IsDBNull(dtQuestions.Rows(0).Item("Question")) Then
lblQuestion1.Text = dtQuestions.Rows(0).Item("Question")
End If
If Not IsDBNull(dtQuestions.Rows(0).Item("Option1")) Then
rblQuestion1.Items(0).Text = dtQuestions.Rows(0).Item("Option1")
End If
If Not IsDBNull(dtQuestions.Rows(0).Item("Option2")) Then
rblQuestion1.Items(1).Text = dtQuestions.Rows(0).Item("Option2")
End If
If Not IsDBNull(dtQuestions.Rows(0).Item("Option3")) Then
rblQuestion1.Items(2).Text = dtQuestions.Rows(0).Item("Option3")
End If
If Not IsDBNull(dtQuestions.Rows(0).Item("Option4")) Then
rblQuestion1.Items(3).Text = dtQuestions.Rows(0).Item("Option4")
End If
End If
Catch ex As Exception
End Try
End If
End Sub
End Class
plz anyone can help me plzzzz