'導入命名空間
Imports System.Data.OleDb
'定義變量
Dim Sql As String
'OleDb連線
Dim SqlAC As OleDbConnection
Dim CmdAC As OleDbCommand
Dim drAC As OleDbDataReader
'打开OleDb連線
Public Sub OpenAC()
SqlAC = New OleDbConnection(" Provider = Microsoft.Jet.OLEDB.4.0;Data Source = DISK.mdb ")
If SqlAC.State = ConnectionState.Closed Then
SqlAC.Open()
End If
CmdAC = New OleDbCommand(Sql, SqlAC)
drAC = CmdAC.ExecuteReader()
End Sub
'关闭OleDb連線
Public Sub CloseAC()
drAC.Close()
If SqlAC.State = ConnectionState.Open Then
SqlAC.Close()
End If
End Sub
Private Sub A1()
Sql = ("SELECT A1 FROM T8 ")
OpenAC()
drAC.Read()
TextBox1.Text = drAC.Item(0)
CloseAC()
End Sub
如果觉得《vb.net連接ACCESS数据库》对你有帮助,请点赞、收藏,并留下你的观点哦!