vb.net(2008)怎样连接Access数据库(2007)

2024-12-21 06:10:31
推荐回答(3个)
回答1:

我没用的2008 ,这是2005里我写的

Dim constr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\zr.mdb;Jet OLEDB:Database Password=1234 "
Dim olecon As OleDbConnection
olecon = New OleDbConnection(constr)
Dim comstr As String = "select * from cb where cname='ww'"
Dim comm As New OleDbCommand(comstr, olecon)
Dim rr As OleDbDataReader
rr = comm.ExecuteReader
If rr.Read() Then
messagebox.show("查询记录成功")
rr.Close()
comm.Dispose()
olecon.Close()
olecon.Dispose()
End If

回答2:

MyConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=数据库;"

回答3:

Dim path As String = "D:\vb\TEXT\Sj\Sj\data\Access_2007.accdb"
Dim conn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & path & ";Jet OLEDB:Database Password=MyDbPassword;"