Hi.

Can some one please help me as i am trying to read from access database and that work with data in a program. I used to work with VB from previous version and now it seems to me there are differencies. If someone can paste a working simple code.
I would like to make a windows form aplication
thank you.

Recommended Answers

All 3 Replies

Hi.

Can some one please help me as i am trying to read from access database and that work with data in a program. I used to work with VB from previous version and now it seems to me there are differencies. If someone can paste a working simple code.
I would like to make a windows form aplication
thank you.

ANS which access version are you using because this pice of code works fin for me if I am using VB.NET 2008 and access 2003.

Private Sub mControlInitialise()
        Dim dbConn As OleDbConnection
        Dim strQuery As String
        Dim dbComm As OleDbCommand
        Dim strConnect As String
        Dim objDataAdapter As OleDbDataAdapter
        Dim objDataSet As New DataSet()

        strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
                     "Data Source=C:/Users/Qinisela/Documents/horizon24.mdb;"
        

        dbConn = New OleDbConnection(strConnect)
        dbConn.Open()
        Try

            strQuery = "SELECT * FROM Product WHERE ProductCode = '" + Page.ClientQueryString() + "'"
            dbComm = New OleDbCommand(strQuery, dbConn)
            objDataAdapter = New OleDbDataAdapter(dbComm)
            objDataAdapter.Fill(objDataSet)
            Me.dgLaptops.DataSource = objDataSet
            Me.dgLaptops.DataBind()

            Try
                If objDataSet.Tables(0).Rows.Count > 0 Then
                    mstrFileName = Server.MapPath("ProductXML/" +   objDataSet.Tables(0).Rows(0)("Xml_Filename").ToString())
                End If

            Finally
            End Try

        Catch ex As Exception

        Finally
            dbConn.Close()
        End Try

    End Sub

ANS which access version are you using because this pice of code works fin for me if I am using VB.NET 2008 and access 2003.

Private Sub mControlInitialise()
        Dim dbConn As OleDbConnection
        Dim strQuery As String
        Dim dbComm As OleDbCommand
        Dim strConnect As String
        Dim objDataAdapter As OleDbDataAdapter
        Dim objDataSet As New DataSet()

        strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
                     "Data Source=C:/Users/Qinisela/Documents/horizon24.mdb;"
        

        dbConn = New OleDbConnection(strConnect)
        dbConn.Open()
        Try

            strQuery = "SELECT * FROM Product WHERE ProductCode = '" + Page.ClientQueryString() + "'"
            dbComm = New OleDbCommand(strQuery, dbConn)
            objDataAdapter = New OleDbDataAdapter(dbComm)
            objDataAdapter.Fill(objDataSet)
            Me.dgLaptops.DataSource = objDataSet
            Me.dgLaptops.DataBind()

            Try
                If objDataSet.Tables(0).Rows.Count > 0 Then
                    mstrFileName = Server.MapPath("ProductXML/" +   objDataSet.Tables(0).Rows(0)("Xml_Filename").ToString())
                End If

            Finally
            End Try

        Catch ex As Exception

        Finally
            dbConn.Close()
        End Try

    End Sub

I am using last version of Access 2007, and i think the code doesn't work here... Actually i would like to get step by step answer if some finds a time for that... so i can understand it and get on on my own :)

Hi.

Can some one please help me as i am trying to read from access database and that work with data in a program. I used to work with VB from previous version and now it seems to me there are differencies. If someone can paste a working simple code.
I would like to make a windows form aplication
thank you.

Hi

Try this

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=D:\Tecnical Stu"& _
"dy\Complete_Code\Ch08\data\NorthWind.mdb"
        Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )
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.