VB.NET 2005,已經實現了continue語法,具體是這樣操作:
成都創新互聯堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都做網站、成都網站制作、成都外貿網站建設、企業官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯網時代的雁塔網站設計、移動媒體設計的需求,幫助企業找到有效的互聯網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
如果 Continue 語句在 Do...Loop 循環中,請將該語句更改為 Continue Do。
如果 Continue 語句在 For...Next 循環中,請將該語句更改為 Continue For。
如果 Continue 語句在 While...End While 循環中,請將該語句更改為 Continue While。
否則,請移除 Continue 語句。
用法:
For i As Integer = 0 To 100
' If i = 50 跳過 Console.Writeline statement
If i = 50 Then Continue For
Console.WriteLine(i.ToString)
Next
' Do While using Continue statement.
Dim ii As Integer = 1
Do While ii 100
ii += 1
' If ii = 50 跳過 Console.Writeline statement
If ii = 50 Then Continue Do
Console.WriteLine(ii.ToString)
Loop
' While using Continue statement.
Dim iii As Integer = 1
While iii 100
iii += 1
' If iii = 50 跳過 Console.Writeline statement
If iii = 50 Then Continue While
Console.WriteLine(iii.ToString)
End While
DT.Rows.ToString未必是指結果集中的所有數據,也許只是一行中所有的,或是一列中所有的
保險起見,可以一格格枚舉
dim a as boolean=true
Dim row As DataRow
For Each row In DT.Rows
Dim column As DataColumn
For Each column In DT.Columns
if row(column).contains("Agree") then a=false
Next column
Next row
if a then
Me.rblAgReject.Items(0).Enabled = False
else
Me.rblAgReject.Items(0).Enabled = True
end if
在VB.NET中VB.NET CASE語句就是比較常用的一種,下面是詳細的介紹和代碼的演示:
1、可以用 Select...Case 語句來替換 If...Then...Else 語句,所不同的是If 和 ElseIf 語句可在每個語句中計算不同的表達式,而 Select 語句對單個表達式只計算一次,然后將其和不同的值比較。
Function?bonus(ByVal?performance?As?Integer,?_??ByVal?salary?As?Decimal)?As?Decimal??
Select?performance??
Case?1??
Return?salary?*?0.1??
Case?2??
Return?salary?*?0.3??
Case?3??
Return?salary?*?0.7??
Case?4??
Return?salary?*?0.9??
Case?5??
Return?salary?*?1.2??
End?Select??
End?Function
2、VB.NET Case語句可包含多個值和某個范圍的值,代碼案例如下:
Function?bonus(ByVal?performance?As?Integer,?_??ByVal?salary?As?Decimal)?As?Decimal??
Select?performance??
Case?1??
Return?salary?*?0.1??
Case?2,3??
Return?salary?*?0.3??
Case?3?To?7??
Return?salary?*?0.7??
Case?8?To?9??
Return?salary?*?0.9??
Case?Is?=?15??
Return?salary?*?1.2??
Case?Else??
Return?0??
End?Select??
End?Function
Dim Cnn As New Data.OleDb.OleDbConnection
Dim DbAdapter As New Data.OleDb.OleDbDataAdapter
Dim Cmd As New Data.OleDb.OleDbCommand
Dim dsAll As New Data.DataSet
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\webapp\test\web.mdb"
Cmd.Connection = Cnn
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'插入
Cmd.CommandText = "insert into main (about) values ('" + TextBox1.Text + "')"
UpdateTable()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
'修改
Dim ids As Integer
ids = 1
Cmd.CommandText = "update main set about='" + TextBox1.Text + "' where id=" + ids.ToString()
UpdateTable()
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
'刪除
Dim ids As Integer
ids = 1
Cmd.CommandText = "delete from main where id=" + ids.ToString()
UpdateTable()
End Sub
Public Sub UpdateTable()
Dim Trans As Data.OleDb.OleDbTransaction
Try
Cnn.Open()
Trans = Cnn.BeginTransaction()
Try
Cmd.Transaction = Trans
Cmd.ExecuteNonQuery()
Trans.Commit()
Catch
Trans.Rollback()
Finally
If (Cnn.State = System.Data.ConnectionState.Open) Then
Cnn.Close()
End If
End Try
Catch
'error message
End Try
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
'顯示
Cmd.CommandText = "select id, about from main"
DbAdapter.SelectCommand = Cmd
DbAdapter.Fill(dsAll, "table1")
If (dsAll.Tables("table1").Rows.Count 0) Then
TextBox1.Text = dsAll.Tables("table1").Rows(0)("about")
Else
TextBox1.Text = ""
End If
End Sub
網站欄目:vb.net常用語句 vbnet using
當前URL:http://vcdvsql.cn/article2/ddccgic.html
成都網站建設公司_創新互聯,為您提供建站公司、網站排名、定制網站、域名注冊、網站策劃、品牌網站設計
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯