[英]visual studio (vb.net) not able to load an access database
这是我的代码
Imports System.Data
Imports System.Data.OleDb
Public Class frmMain
' database connection string
Const CONNECTION_STRING As String = "Provider=Microsoft.ACE.OLEDB.12.0; data source=business.accdb"
' database connectivity objects
Dim dbConnection As OleDbConnection
Dim dbAdapter As OleDbDataAdapter
Dim dbDataSet As DataSet
' current record index
Dim recordIndex As Integer = 0
Private Sub updateTextboxes()
txtCustomerID.Text = Convert.ToString(dbDataSet.Tables("Customers").Rows(recordIndex).Item("CustomerID"))
txtName.Text = Convert.ToString(dbDataSet.Tables("Customers").Rows(recordIndex).Item("Name"))
txtAddress.Text = Convert.ToString(dbDataSet.Tables("Customers").Rows(recordIndex).Item("Address"))
txtCity.Text = Convert.ToString(dbDataSet.Tables("Customers").Rows(recordIndex).Item("City"))
txtProvince.Text = Convert.ToString(dbDataSet.Tables("Customers").Rows(recordIndex).Item("Province"))
txtPostal.Text = Convert.ToString(dbDataSet.Tables("Customers").Rows(recordIndex).Item("Postal"))
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
' create connection to database
dbConnection = New OleDbConnection(CONNECTION_STRING)
dbConnection.Open()
' setup and construct the data adapter
dbAdapter = New OleDbDataAdapter("SELECT * FROM Customers", dbConnection)
' construct DataSet object to hold the returned data
dbDataSet = New DataSet()
' make it happen!
dbAdapter.Fill(dbDataSet, "Customers")
' use the data!
updateTextboxes()
' close the connection
dbConnection.Close()
End Sub
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
' increment record index by one
recordIndex = recordIndex + 1
' am I past the last record?
If (recordIndex > (dbDataSet.Tables("Customers").Rows.Count - 1)) Then
recordIndex = 0
End If
' update the textboxes
updateTextboxes()
End Sub
End Class
该代码应该可以工作,它是由我的讲师提供的一个课堂示例。 上周,它在我的笔记本电脑上运行良好。 我正在尝试将其用作我们最终项目的参考,但是现在它将无法运行。 该项目需要使用代码导入数据库,因此在VS中使用“添加新数据源”工具或类似工具不是可行的解决方案。 我没有收到任何错误消息。 我在Visual Studio中单击“启动”,它似乎正在加载程序片刻(启动按钮变灰,加载光标出现,等等),然后停止。
这是我的调试输出。
线程0x1504已退出,代码为0(0x0)。
'dbAccessDemo.vshost.exe'(CLR v4.0.30319:dbAccessDemo.vshost.exe):已加载'C:\\ Users \\ Kat \\ Desktop \\ business_completeLesson \\ dbAccessDemo \\ dbAccessDemo \\ bin \\ Debug \\ dbAccessDemo.exe'。 符号已加载。
'dbAccessDemo.vshost.exe'(CLR v4.0.30319:dbAccessDemo.vshost.exe):已加载'C:\\ WINDOWS \\ Microsoft.Net \\ assembly \\ GAC_MSIL \\ Accessibility \\ v4.0_4.0.0.0__b03f5f7f11d50a3a \\ Accessibility.dll'。 找不到或打开PDB文件。
'dbAccessDemo.vshost.exe'(CLR v4.0.30319:dbAccessDemo.vshost.exe):已加载'C:\\ WINDOWS \\ Microsoft.Net \\ assembly \\ GAC_MSIL \\ System.Runtime.Remoting \\ v4.0_4.0.0.0__b77a5c561934e089 \\ System .Runtime.Remoting.dll”。 跳过的加载符号。 模块已优化,调试器选项“ Just My Code”已启用。
'dbAccessDemo.vshost.exe'(CLR v4.0.30319:dbAccessDemo.vshost.exe):已加载'C:\\ WINDOWS \\ Microsoft.Net \\ assembly \\ GAC_32 \\ System.Transactions \\ v4.0_4.0.0.0__b77a5c561934e089 \\ System.Transactions .dll”。 跳过的加载符号。 模块已优化,调试器选项“ Just My Code”已启用。
程序“ [9984] dbAccessDemo.vshost.exe”已退出,代码为-1066598274(0xc06d007e)“未找到模块”。
从上周(我能够运行它)到现在,我对Office 365的免费试用期已到期。 我卸载了它,并安装了我的大学通过Dreamspark提供的Access 2016副本。 我猜测这可能与我的问题有关,但除此之外,我迷路了。
我正在使用Visual Studio Express 2015和Windows 10。
编辑
解决了我自己的问题。 我下载并安装了Access数据库引擎2007 ,现在它可以完美运行。
解决了我自己的问题。 我下载并安装了Access数据库引擎2007 ,现在它可以完美运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.