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.

Edited 6 Years Ago by dr.e: n/a

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

Edited 6 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

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 :)

Edited 6 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

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 )

Edited 6 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

This article has been dead for over six months. Start a new discussion instead.