tags:

views:

49

answers:

1

I am trying to debug my program and I am getting an OleDBException Was Unhandled. It then goes to the path where the error is located. The executable is listed in the bin file and I have re-built and built the application several times. The application is supposed to extract data from an external MS Access database. Note my code:

Public Class frmSpanishFoodStoreInventory

   Private Sub StoreInventoryBindingNavigatorSaveItem_Click(ByVal sender As     System.Object, ByVal e As System.EventArgs) Handles     StoreInventoryBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.StoreInventoryBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.Spanishfood2DataSet)

    End Sub

    Private Sub frmSpanishFoodStoreInventory_Load(ByVal sender As System.Object, ByVal     e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into     the 'spanishfood2DataSet.StoreInventory' table. You can move, or remove it, as needed.
        Me.StoreInventoryTableAdapter.Fill(Me.Spanishfood2DataSet.StoreInventory)


        ' In case of an error the Try Catch Block will present an error message.

        Try
            Me.StoreInventoryTableAdapter.Fill(Me.Spanishfood2DataSet.StoreInventory)
        Catch ex As Exception
            MsgBox("Los archivos de base de datos son inasequibles", , "Error")
        End Try
        Me.Close()



    End Sub

    Private Sub btnComputeTheTotalValueOfInventory_Click(ByVal sender As     System.Object, ByVal e As System.EventArgs) Handles     btnComputeTheTotalValueOfInventory.Click


        Dim strSql As String = "SELECT * FROM SpanishFoodStoreInventory "

        'strPath provides the database type and path of the SpanishFood database.
        Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;"     & "..\spanishfood2.accdb"
        Dim odaInventory As New OleDb.OleDbDataAdapter(strSql, strPath)
        Dim DatCost As New DataTable
        Dim intCount As Integer
        Dim decTotalCost As Decimal = 0D

        'The DataTable name datCost is filled with the data
        odaInventory.Fill(DatCost)

        'The connection to the databsise is disconnected
        odaInventory.Dispose()

        For intCount = 0 To DatCost.Rows.Count - 1
            decTotalCost += Convert.ToDecimal(DatCost.Rows(intCount)("Food Cost"))
        Next

        Me.lblTotalCost.Visible = True
        Me.lblTotalCost.Text = "El coste de recorrido aprobado total es " &     decTotalCost.ToString("C")

    End Sub
End Class
A: 

I had to use a relative reference for the file.. Once i did that it worked fine.

Michael