网站建设资讯

NEWS

网站建设资讯

vb.net例程,VBNET

求一个用VB.net操作access数据库的例程

Imports System

创新互联建站:从2013年创立为各行业开拓出企业自己的“网站建设”服务,为超过千家公司企业提供了专业的成都做网站、网站设计、网页设计和网站推广服务, 按需制作由设计师亲自精心设计,设计的效果完全按照客户的要求,并适当的提出合理的建议,拥有的视觉效果,策划师分析客户的同行竞争对手,根据客户的实际情况给出合理的网站构架,制作客户同行业具有领先地位的。

Imports System.Drawing

Imports System.ComponentModel

Imports System.Windows.Forms

Imports System.Data.OleDb

Imports System.Data

Public Class Form1

Inherits Form

Private components As System.ComponentModel.Container = Nothing

Private WithEvents lastrec As Button

Private WithEvents nextrec As Button

Private WithEvents previousrec As Button

Private WithEvents firstrec As Button

Private t_books As TextBox

Private t_nl As TextBox

Private t_xb As TextBox

Private t_xm As TextBox

Private t_id As TextBox

Private l_books As Label

Private l_nl As Label

Private l_xb As Label

Private l_xm As Label

Private l_id As Label

Private label1 As Label

Private myDataSet As DataSet

Private WithEvents button1 As Button

Private WithEvents button2 As Button

Private WithEvents button3 As Button

Private WithEvents button4 As Button

Private myBind As BindingManagerBase

Public Sub New ( )

MyBase.New ( )

GetConnected ( )

InitializeComponent ( )

End Sub

'清除在程序中使用过的资源

Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose ( )

End If

End If

MyBase.Dispose ( disposing )

End Sub

Public Sub GetConnected ( )

'创建一个数据连接

Dim strCon As String = " Provider = Microsoft.Jet.OLEDB.4.0 ;

Data Source = db.mdb "

Dim myConn As OleDbConnection = New OleDbConnection ( )

myConn.ConnectionString = strCon

Dim strCom As String = " SELECT * FROM person "

'创建一个 DataSet

myDataSet = New DataSet ( )

myConn.Open ( )

'通过OleDbDataAdapter对象得到一个数据集

Dim myCommand As OleDbDataAdapter = New OleDbDataAdapter

( strCom , myConn )

'把Dataset绑定books数据表

myCommand.Fill ( myDataSet , "person" )

'关闭此数据连接

myConn.Close ( )

End Sub

'插入数据记录操作代码

Private Sub button2_Click (ByVal sender As Object , _

ByVal e As System.EventArgs) Handles button2.Click

'判断所有字段是否添完,添完则执行,反之弹出提示

If ( t_id.Text "" And t_xm.Text ""

And t_xb.Text "" And t_nl.Text ""

And t_books.Text "" ) Then

Dim myConn1 As String = " Provider = Microsoft.Jet.OLEDB.4.0 ;

Data Source = db.mdb"

Dim myConn As OleDbConnection = New OleDbConnection ( myConn1 )

myConn.Open ( )

Dim strInsert As String = " INSERT INTO person ( id , xm , xb , nl

, zip ) VALUES ( " _

t_id.Text + " , '" _

t_xm.Text + "' , '" _

t_xb.Text + "' , " _

t_nl.Text + " , " _

t_books.Text + ")"

Dim inst As OleDbCommand = New OleDbCommand ( strInsert , myConn )

inst.ExecuteNonQuery ( )

myConn.Close ( )

myDataSet.Tables ( "person" ).Rows ( myBind.Position ).BeginEdit ( )

myDataSet.Tables ( "person" ).Rows ( myBind.Position ).EndEdit ( )

myDataSet.Tables ( "person" ).AcceptChanges ( )

Else

MessageBox.Show ( "必须填满所有字段值!" , "错误!" )

End If

End Sub

VB.net中类的实例化

1.不正确

Dim abc As myClass,定义一个可以引用myClass类型对象的变量abc。这个abc变量存在于栈上。

abc=New myClass。New myClass创建myClass实例对象,这个对象存在于托管堆上。然后(同时)让abc引用(指向)这个对象。

abc变量在栈上,而对象在托管堆上。

abc储存的是对象的地址,而不是对象本身。

看下面的代码

Dim a As myClass,b As myClass,c As myClass

a=New myClass

b=a

c=a

整个过程中只创建了一个myClass对象,位于托管堆上。

三个myClass类型的变量a、b、c位于栈上,都指向了这一个myClass对象

2.类的成员分 实例成员 和 静态成员

实例成员 必须在实例对象上调用

静态成员 可以直接调用,不需要实例对象。

关于VB.NET进度条的实例

该实例有很多实现方法,下面介绍一种不同的给你:

首先要在窗体中载入以下控件:progressbar(进度条),label(用来实时显示文本提示),两个timer(分别控制进度条进度的增减),然后用以下代码就能实现:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Timer1.Enabled = True

Timer1.Interval = 500

Timer2.Interval = 500

ProgressBar1.Value = 0

ProgressBar1.Maximum = 100

ProgressBar1.Minimum = 0

End Sub

'上述过程是设置控件的初始值,也可以在属性面板设置

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

ProgressBar1.Value += 1

Label1.Text = "当前完成" ProgressBar1.Value "%"

If (ProgressBar1.Value = 100) Then

Timer1.Enabled = False

Timer2.Enabled = True

End If

End Sub

'timer1用来控制进度的增加

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

ProgressBar1.Value -= 1

Label1.Text = "当前完成" ProgressBar1.Value "%"

If (ProgressBar1.Value = 0) Then

Timer1.Enabled = True

Timer2.Enabled = False

End If

End Sub

'time2用来控制进度的减少

End Class


分享标题:vb.net例程,VBNET
转载注明:http://njwzjz.com/article/dsisjhc.html