[英]visual studio (vb.net) not able to load an access database
Here's my code 这是我的代码
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
The code should work, it was provided by my instructor as an in-class example. 该代码应该可以工作,它是由我的讲师提供的一个课堂示例。 It ran perfectly on my laptop last week.
上周,它在我的笔记本电脑上运行良好。 I'm trying to use it as a reference for our final project, but now it won't run.
我正在尝试将其用作我们最终项目的参考,但是现在它将无法运行。 The project requires importing the database using code, so using the "add new datasource" tool in VS, or anything similar, isn't a viable solution.
该项目需要使用代码导入数据库,因此在VS中使用“添加新数据源”工具或类似工具不是可行的解决方案。 I don't get any kind of error message.
我没有收到任何错误消息。 I click "start" in Visual Studio and it appears to be loading the program for a moment (start button is greyed out, loading cursor appears, etc.) before stopping.
我在Visual Studio中单击“启动”,它似乎正在加载程序片刻(启动按钮变灰,加载光标出现,等等),然后停止。
Here's my debug output. 这是我的调试输出。
The thread 0x1504 has exited with code 0 (0x0).
线程0x1504已退出,代码为0(0x0)。
'dbAccessDemo.vshost.exe' (CLR v4.0.30319: dbAccessDemo.vshost.exe): Loaded 'C:\\Users\\Kat\\Desktop\\business_completeLesson\\dbAccessDemo\\dbAccessDemo\\bin\\Debug\\dbAccessDemo.exe'.
'dbAccessDemo.vshost.exe'(CLR v4.0.30319:dbAccessDemo.vshost.exe):已加载'C:\\ Users \\ Kat \\ Desktop \\ business_completeLesson \\ dbAccessDemo \\ dbAccessDemo \\ bin \\ Debug \\ dbAccessDemo.exe'。 Symbols loaded.
符号已加载。
'dbAccessDemo.vshost.exe' (CLR v4.0.30319: dbAccessDemo.vshost.exe): Loaded 'C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\Accessibility\\v4.0_4.0.0.0__b03f5f7f11d50a3a\\Accessibility.dll'.
'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'。 Cannot find or open the PDB file.
找不到或打开PDB文件。
'dbAccessDemo.vshost.exe' (CLR v4.0.30319: dbAccessDemo.vshost.exe): Loaded 'C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Runtime.Remoting\\v4.0_4.0.0.0__b77a5c561934e089\\System.Runtime.Remoting.dll'.
'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”。 Skipped loading symbols.
跳过的加载符号。 Module is optimized and the debugger option 'Just My Code' is enabled.
模块已优化,调试器选项“ Just My Code”已启用。
'dbAccessDemo.vshost.exe' (CLR v4.0.30319: dbAccessDemo.vshost.exe): Loaded 'C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_32\\System.Transactions\\v4.0_4.0.0.0__b77a5c561934e089\\System.Transactions.dll'.
'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”。 Skipped loading symbols.
跳过的加载符号。 Module is optimized and the debugger option 'Just My Code' is enabled.
模块已优化,调试器选项“ Just My Code”已启用。
The program '[9984] dbAccessDemo.vshost.exe' has exited with code -1066598274 (0xc06d007e) 'Module not found'.
程序“ [9984] dbAccessDemo.vshost.exe”已退出,代码为-1066598274(0xc06d007e)“未找到模块”。
Between last week (when I was able to run it) and now, my free trial of Office 365 expired. 从上周(我能够运行它)到现在,我对Office 365的免费试用期已到期。 I uninstalled it, and installed the copy of Access 2016 provided by my college via Dreamspark.
我卸载了它,并安装了我的大学通过Dreamspark提供的Access 2016副本。 I'm guessing that might have something to do with my problem, but other than that I'm lost.
我猜测这可能与我的问题有关,但除此之外,我迷路了。
I'm using Visual Studio Express 2015, and Windows 10. 我正在使用Visual Studio Express 2015和Windows 10。
EDIT 编辑
Solved my own issue. 解决了我自己的问题。 I downloaded+installed Access Database Engine 2007 and now it works perfectly.
我下载并安装了Access数据库引擎2007 ,现在它可以完美运行。
Solved my own issue. 解决了我自己的问题。 I downloaded+installed Access Database Engine 2007 and now it works perfectly.
我下载并安装了Access数据库引擎2007 ,现在它可以完美运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.