资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net最基础的语句,VB常用语句

VB.NET流程控制语句有哪些

有很多啊!像If...else..,For...Next,Do...Loop等

创新互联公司主营怒江州网站建设的网络公司,主营网站建设方案,手机APP定制开发,怒江州h5小程序开发搭建,怒江州网站营销推广欢迎怒江州等地区企业咨询

要详细的看MSDN吧:

高分求.net里vb语法操作数据库基本语句

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的 把重点的语句注释下就行了

'''两段程序就是利用.net的连接对象的功能来完成登录的实例

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click 'start按钮触发的函数

Dim schclass As String = Trim(txtClass.Text) ‘将txtClass里文本赋值给变量schclass

Dim selestr As String

’提示用户txtClass文本框不能为空

If schclass "" Then

selestr = "班级='" schclass "'"

Else

MsgBox("请输入班级名称", 64, "提示") ‘ 显示保存成功提示信息

End If

‘创建一个DataView对象,即将数据集DataSet11里的学生成绩表的DefaultView实例化

Dim dvresult As DataView = DataSet11.学生成绩.DefaultView

’按学号字段排序

dvresult.Sort = "学号"

‘按刚才txtClass里输入的班级查询

dvresult.RowFilter = selestr

dvresult.RowStateFilter = DataViewRowState.CurrentRows

’然后将筛选的结果输入到datagrid上

DataGrid1.DataSource = dvresult

End Sub

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click ‘ok按钮触发的函数

’如果txtUserName或txtPass文本框为空,提示并中断函数

If txtUserName.Text = "" Or txtPass.Text = "" Then

Response.Write("script language=vbscriptalert""用户名或密码不能为空!""/script")

Exit Sub

End If

‘定义链接、执行、阅读 对象

Dim mycon As New OleDbConnection

Dim mycmd As New OleDbCommand

Dim reader As OleDbDataReader

’给连接对象赋值连接字符串,access类型的。

mycon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _

Server.MapPath("Msg.mdb")

‘打开连接对象

mycon.Open()

’将连接对象复制到执行对象上

mycmd.Connection = mycon

‘然后就给执行对象赋值执行类型和执行语句

mycmd.CommandType = CommandType.Text

mycmd.CommandText = "Select * from myuser Where 用户名='" txtUserName.Text "'" " and 密码='" txtPass.Text "'"

’然后将执行对象的监听实例化

reader = mycmd.ExecuteReader()

‘如果执行不成功,即没有得到结果集就提示否则将结果集的用户名赋值给一个session以供其他页面使用

If reader.Read = False Then

Response.Write("script language=vbscriptalert""用户名或密码错,你不能登录!""/script")

Else

Session("username") = reader("用户名")

Response.Redirect("lwmsg.aspx")

End If

’关闭监听

reader.Close()

‘关闭连接

mycon.Close()

End Sub


分享题目:vb.net最基础的语句,VB常用语句
分享网址:http://cdkjz.cn/article/phipdo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220