[英]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.