简体   繁体   中英

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. 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.

Here's my debug output.

The thread 0x1504 has exited with code 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'. 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'. Cannot find or open the PDB file.

'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'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'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'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

The program '[9984] dbAccessDemo.vshost.exe' has exited with code -1066598274 (0xc06d007e) 'Module not found'.

Between last week (when I was able to run it) and now, my free trial of Office 365 expired. I uninstalled it, and installed the copy of Access 2016 provided by my college via Dreamspark. 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.

EDIT

Solved my own issue. I downloaded+installed Access Database Engine 2007 and now it works perfectly.

Solved my own issue. I downloaded+installed Access Database Engine 2007 and now it works perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM