本文介绍了我该如何使用计数器呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的代码,我正在做在线考试的项目。我可以在我的项目中使用计数器..
The following is my code, I am doing project on online examination.how i can use the counter in my project..
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
'For Question 1
If Not IsDBNull(dtQuestions.Rows(0).Item("Question")) Then
lblQuestion1.Text = dtQuestions.Rows(1).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
推荐答案
int i=0
foreach(Datarow dr in dtQuestions.Rows)
{
i++;
If Not IsDBNull(dtQuestions.Rows(i).Item("Question")) Then
Question_No.Text = dtQuestions.Rows(i).Item("Question_ID")
End If
If Not IsDBNull(dtQuestions.Rows(i).Item("Question")) Then
lblQuestion1.Text = dtQuestions.Rows(i).Item("Question")
End If
If Not IsDBNull(dtQuestions.Rows(i).Item("Option1")) Then
rblQuestion1.Items(0).Text = dtQuestions.Rows(i).Item("Option1")
End If
If Not IsDBNull(dtQuestions.Rows(i).Item("Option2")) Then
rblQuestion1.Items(1).Text = dtQuestions.Rows(i).Item("Option2")
End If
If Not IsDBNull(dtQuestions.Rows(i).Item("Option3")) Then
rblQuestion1.Items(2).Text = dtQuestions.Rows(i).Item("Option3")
End If
If Not IsDBNull(dtQuestions.Rows(i).Item("Option4")) Then
rblQuestion1.Items(3).Text = dtQuestions.Rows(i).Item("Option4")
End If
End If
}
这篇关于我该如何使用计数器呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!