Hi all i am havin a problem with my Jet oleDB connection i am getting an error and i am not sure if my code is completly wrong or it is a small problem any help would be great.

This is the erorr i get:

An unhandled exception of type 'System.TypeInitializationException' occurred in Pizza Project.exe

Additional information: The type initializer for 'Pizza_Project.dataAccess' threw an exception.

This error happens when i try to get the data from my Access 2003 database and put it into a datagrid.

Module dataAccess
    Public TotalCost
    Public m_strToppings As String
    Public m_strPizzaType As String

    ' Description: link a VB interface with a 2003 Access Database
    ' This is my connection String
    Public constring()

    Dim ConnString As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source" = CStr(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "PizzaProject\PizzaDB.mdb")
    


    Dim DBCon As New OleDb.OleDbConnection(ConnString)

    Sub OpenDatabaseConnction() 'to open connection

        If DBCon.State = ConnectionState.Closed Then
            DBCon.Open()
            MessageBox.Show("Open")
        End If
    End Sub

    Sub CloseDatabaseConnction() 'to close connection

        If DBCon.State = ConnectionState.Open Then
            DBCon.Close()

        End If
    End Sub
    Function ShowALLCustomerAccountDetails() As DataSet  ' To send the info to a datagrid

        OpenDatabaseConnction()



        Dim rs As New ADODB.Recordset()
        rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
        rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic

        rs.Open("select * from CustomerAccountDetails", ConnString)

        rs.ActiveConnection = Nothing

        CloseDatabaseConnction()

        Dim da As New System.Data.OleDb.OleDbDataAdapter()
        Dim ds As New DataSet()
        da.Fill(ds, rs, "CustomerAccountDetails")
        Return ds


    End Function

this is the button click event to show the data in the data grid.

Public Class frmEditCustomerDetails

    Private Sub btnShowDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDetails.Click
        Dim ds As DataSet ' Show details in datagrid

        ds = dataAccess.ShowALLCustomerAccountDetails()
        With DataGridView1
            .DataSource = ds.Tables("CustomerAccountDetails")
        End With
    End Sub
End Class

Recommended Answers

All 2 Replies

Member Avatar for Unhnd_Exception

Data Source needs and = sign and the = sign you have needs to be an &

Dim ConnString As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source =" & CStr(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "PizzaProject\PizzaDB.mdb")
commented: Helpful and a nice guy +1

Data Source needs and = sign and the = sign you have needs to be an &

Dim ConnString As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source =" & CStr(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "PizzaProject\PizzaDB.mdb")

Hey i got this to work when i put it on the desktop but not when i put it into a folder any ideas:

The code:

Dim ConnString As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source =" & CStr(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Pizza.mdb")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.