用vb.net操作access数据库
哪位大神能给提供一个用vb.net的代码调用、修改、增删access数据库的示例呢?我只会用vb.net提供的插件来实现这些功能。我的邮箱,tnred@sina.com,...
哪位大神能给提供一个用vb.net的代码调用、修改、增删access数据库的示例呢?
我只会用vb.net提供的插件来实现这些功能。
我的邮箱,tnred@sina.com,能打包发给我就更好了,谢谢了~
还是没实现修改和删除的操作吧? 展开
我只会用vb.net提供的插件来实现这些功能。
我的邮箱,tnred@sina.com,能打包发给我就更好了,谢谢了~
还是没实现修改和删除的操作吧? 展开
展开全部
mports 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
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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询