当我尝试使用 VB.NET 连接到 Microsoft Access DB 时出现错误。我在网上看到了很多例子。我的代码看起来像那些示例,但是我收到一条构建错误消息,说明:
未定义类型“System.Data.OleDb.OleDbConnection”。
我尝试为 ... 添加某种导入语句,system.data.oledb
但这似乎不起作用。我的代码如下。这是一个基本连接,所以我想我缺少某种插件、库或设置。任何和所有的帮助将不胜感激。
Public Function TestMain(ByVal args() As Object) As Object
' Connection String to MS Access DB
Dim connectStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\Users\DMalerman\keyword.accdb;" & _
"Persist Security Info=False;"
MsgBox(connectStr)
' Create connection to the db
Using connection As New System.Data.OleDb.OleDbConnection(connectStr)
' Create the SQL Query
Dim readQuery As String = "Select KeywordDriver.ScriptName from KeywordDriver " & _
"where KeywordDriver.Keyword = test"
Dim queryCommand As New System.Data.OleDb.OleDbCommand(readQuery, connection)
'Open the Connection
connection.Open()
' Query the Database
Dim dbReader As System.Data.OleDb.OleDbDataReader = queryCommand.ExecuteReader()
' Loop until there is nothing left to read
While dbReader.Read()
Dim sKeyword As String = ""
sKeyword = dbReader.GetString(0)
MsgBox(sKeyword)
End While
' Close the Reader
dbReader.Close()
End Using
Return Nothing
End Function