你這是vb.net的代碼,vb中不允許那么寫:
創(chuàng)新互聯(lián)公司專注于羅江企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站設(shè)計(jì),購(gòu)物商城網(wǎng)站建設(shè)。羅江網(wǎng)站建設(shè)公司,為羅江等地區(qū)提供建站服務(wù)。全流程按需制作網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
Dim
strdx()
As
String
=
{"0",
"0",
"0"}
'定義個(gè)數(shù)組,從后面的值能看的出最大下標(biāo)是2,也就是strdx(0),strdx(1)和strdx(2),3個(gè)的默認(rèn)值都為0
Dim
calcount1
As
String
=
"0"
'定義個(gè)字符串變量
Dim
calcount2
As
String
=
"0"
Dim
strvalue
As
Boolean
=
False
'定義strvalue為bool值,改類型變量只有true和false
2種值
If
strdx(0)
=
"0"
Then
TextBox1.Text
=
strdx(0)
"."
這是字符串連接符號(hào),和"+"的區(qū)別是,他把左右2邊的內(nèi)容直接連接的,而"+"可能會(huì)編程運(yùn)算符,例如
2
3
=
"23"
而
2
+
3
=
5
ElseIf
strvalue
=
False
Then
strdx(0)
=
strdx(0)
"0"
TextBox1.Text
=
strdx(0)
"."
strvalue
=
True
Else
strdx(0)
=
strdx(0)
"0"
TextBox1.Text
=
strdx(0)
Select
Case
calcount1
'
這里開(kāi)始是分支語(yǔ)句
Case
"+"
TextBox1.Text
=
Str(Val(strdx(1))
+
Val(strdx(0)))
#If...Then...#Else 指令
根據(jù)條件編譯選定的 Visual Basic 代碼塊,需要有#Const 配對(duì),一般要先用#Const 定義條件編譯器常量
'以下是例子
Module Module1
#Const i = 60
Sub Main()
#If i 30 Then
Console.WriteLine("???") '如果用#Const定義了i,該句語(yǔ)句才會(huì)執(zhí)行,假如用的是private i as integer=60定義,該語(yǔ)句不會(huì)被執(zhí)行
#End If
End Sub
End Module
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
順序應(yīng)該是先Connection的Open
con.ConnectionString = constr
con.Open()
dc = New OleDbDataAdapter(sql, constr)
另外你的SQL語(yǔ)句好像有點(diǎn)問(wèn)題,表名不加單引號(hào)
不一樣的,主要的關(guān)鍵字差不多,語(yǔ)法有一些有變化
vb.net與vb語(yǔ)法的一個(gè)很大不同——oop設(shè)計(jì)
例如
sMyString = Mid(sMyString,3,4)
現(xiàn)在,它可以被替換為:
sMyString = sMyString.substring(3,4)
前者是二維矩形數(shù)組,即傳統(tǒng)的二維數(shù)組,后者是交錯(cuò)數(shù)組.
有時(shí),應(yīng)用程序中的數(shù)據(jù)結(jié)構(gòu)是兩維的但不是矩形。例如,一個(gè)月份的數(shù)組,其每個(gè)元素又是天數(shù)的數(shù)組。由于不同的月份有不同的天數(shù),元素不能構(gòu)成一個(gè)矩形的兩維數(shù)組。在這種情況下,可以使用交錯(cuò)數(shù)組而不是多維數(shù)組。
網(wǎng)站欄目:.net++vb語(yǔ)法 VBNET的編程機(jī)制
地址分享:http://m.rwnh.cn/article2/hpjioc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、網(wǎng)站策劃、軟件開(kāi)發(fā)、營(yíng)銷型網(wǎng)站建設(shè)、定制開(kāi)發(fā)、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)