asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

ASP.NET入门教程 9.2.3 循环[6]


发布日期:2019年03月24日
 
ASP.NET入门教程 9.2.3 循环[6]

下面通过介绍Wrox United的工作原理给出了循环和测试的一个示例在接下来的试一试部分您可以浏览比赛日程从而看到进球数以及赢球输球或平局的场次

)创建一个新的Web Form命名为Decisionsaspx并将其设置为起始页面记得在创建Web Form时要将代码放到一个单独的文件中

)添加个标签和一些文本得到页面可以直接在页面上输入文本并确保由上而下逐个添加标签因此Label在顶端而Label 在底端

)创建Page Load事件过程通过打开代码文件并从第一个列表中选择PageEvents从第二个列表中选择Page Load在Page Load事件中添加以下代码(记住如果不想手工输入的话则可以从已经完成的示例中复制这些代码)

Dim conn As New SqlConnection(ConfigurationManagerConnectionStrings(WroxUnited)ConnectionString)

Dim cmd As New SqlCommand(select * from Fixtures conn)

Dim rdr As SqlDataReader

Dim wins As Integer =

Dim losses As Integer =

Dim draws As Integer =

Dim goalsFor As Integer =

Dim goalsAgainst As Integer =

Dim winRatio As Integer

connOpen()

rdr = cmdExecuteReader(CommandBehaviorCloseConnection)

While rdrRead

goalsFor += ConvertToInt(rdr(GoalsFor))

goalsAgainst += ConvertToInt(rdr(GoalsAgainst))

If goalsFor > goalsAgainst Then

wins +=

ElseIf goalsFor < goalsAgainst Then

losses +=

Else

draws +=

End If

End While

LabelText = winsToString()

LabelText = lossesToString()

LabelText = drawsToString()

LabelText = goalsForToString()

LabelText = goalsAgainstToString()

If losses = Then

LabelText = No losses a perfect season

Return

End If

winRatio = ConvertToInt((wins / losses) * )

Select Case winRatio

Case

LabelText = No wins Relegation is a certainty

Case Is <

LabelText = Less than % Very poor

Case Is <

LabelText = Under half Could do better

Case Is <

LabelText = Winning more than losing Excellent

Case Else

LabelText = A high ratio near the top of the table

End Select

End Sub

End Class

[] [] [] [] [] [] [] []

               

上一篇:ASP.NET入门教程 9.2.3 循环[3]

下一篇:ASP.NET入门教程 9.2.3 循环[7]