vbnetascc的简单介绍

VBNET ACCESS操作方法Imports System.Data.OleDb
Public Class Form1
Dim cn As OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As DataSet
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim cnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\persons.mdb;Persist Security Info=False"
cn = New OleDbConnection(cnStr)
Dim sql As String = "select * from grade"
da = New OleDbDataAdapter(sql, cn)
ds = New DataSet
da.Fill(ds, "grade")
DataGridView1.DataSource = ds.Tables(0)
End Sub
End Class
解释vbnetascc:
Dim cnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\persons.mdb;Persist Security Info=False"
这段是创建链接字符串vbnetascc,vbnetascc你可以根据自己数据库实际存放位置进行修改
Dim sql As String = "select * from grade"
这是数据库查询语句,vbnetascc你可以根据实际情况修改下
Dim sql As String = "select * from grade"
da = New OleDbDataAdapter(sql, cn)
ds = New DataSet
da.Fill(ds, "grade")
DataGridView1.DataSource = ds.Tables(0)
这是执行查询语句后,将查询vbnetascc的结果存入datagridview中
用vb.net操作access数据库mportsSystem.Drawing
ImportsSystem.ComponentModel
ImportsSystem.Windows.Forms
ImportsSystem.Data.OleDb
ImportsSystem.Data
PublicClassForm1
InheritsForm
PrivatecomponentsAsSystem.ComponentModel.Container=Nothing
PrivateWithEventslastrecAsButton
PrivateWithEventsnextrecAsButton
PrivateWithEventspreviousrecAsButton
PrivateWithEventsfirstrecAsButton
Privatet_booksAsTextBox
Privatet_nlAsTextBox
Privatet_xbAsTextBox
Privatet_xmAsTextBox
Privatet_idAsTextBox
Privatel_booksAsLabel
Privatel_nlAsLabel
Privatel_xbAsLabel
Privatel_xmAsLabel
Privatel_idAsLabel
Privatelabel1AsLabel
PrivatemyDataSetAsDataSet
PrivateWithEventsbutton1AsButton
PrivateWithEventsbutton2AsButton
PrivateWithEventsbutton3AsButton
PrivateWithEventsbutton4AsButton
PrivatemyBindAsBindingManagerBase
PublicSubNew()
MyBase.New()
GetConnected()
【vbnetascc的简单介绍】InitializeComponent()
EndSub
'清除在程序中使用过的资源
ProtectedOverloadsOverridesSubDispose(ByValdisposingAsBoolean)
IfdisposingThen
IfNot(componentsIsNothing)Then
components.Dispose()
EndIf
EndIf
MyBase.Dispose(disposing)
EndSub
PublicSubGetConnected()
'创建一个数据连接
DimstrConAsString="Provider=Microsoft.Jet.OLEDB.4.0;
DataSource=db.mdb"
DimmyConnAsOleDbConnection=NewOleDbConnection()
myConn.ConnectionString=strCon
DimstrComAsString="SELECT*FROMperson"
'创建一个DataSet
myDataSet=NewDataSet()
myConn.Open()
'通过OleDbDataAdapter对象得到一个数据集
DimmyCommandAsOleDbDataAdapter=NewOleDbDataAdapter
(strCom,myConn)
'把Dataset绑定books数据表
myCommand.Fill(myDataSet,"person")
'关闭此数据连接
myConn.Close()
EndSub
'插入数据记录操作代码
PrivateSubbutton2_Click(ByValsenderAsObject,_
ByValeAsSystem.EventArgs)Handlesbutton2.Click
'判断所有字段是否添完,添完则执行,反之弹出提示
If(t_id.Text""Andt_xm.Text""
Andt_xb.Text""Andt_nl.Text""
Andt_books.Text"")Then
DimmyConn1AsString="Provider=Microsoft.Jet.OLEDB.4.0;
DataSource=db.mdb"
DimmyConnAsOleDbConnection=NewOleDbConnection(myConn1)
myConn.Open()
DimstrInsertAsString="INSERTINTOperson(id,xm,xb,nl
,zip)VALUES("_
t_id.Text+",'"_
t_xm.Text+"','"_
t_xb.Text+"',"_
t_nl.Text+","_
t_books.Text+")"
DiminstAsOleDbCommand=NewOleDbCommand(strInsert,myConn)

推荐阅读