none
Saving data to access database RRS feed

  • Question

  • I am using Windows 10 with Office 2016 and Visual Studio 2017. I have a simple application to save details to access database using the following code

    Try
                Dim sqlconn As New OleDb.OleDbConnection
                Dim sqlquery As New OleDb.OleDbCommand
                Dim connString As String
                connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Business.accdb"
                sqlconn.ConnectionString = connString
                sqlquery.Connection = sqlconn
                sqlconn.Open()
                sqlquery.CommandText = "INSERT INTO tbProducts(ProductName, MRP)VALUES('@ProductName', '@MRP')"
                sqlquery.Parameters.AddWithValue("@ProductName", TextBox1.Text)
                sqlquery.Parameters.AddWithValue("@MRP", TextBox2.Text)
                sqlquery.ExecuteNonQuery()
                sqlconn.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
            MsgBox("saved")

    But I get the following error

    What may be going wrong here ?


    Monday, March 18, 2019 4:19 PM

Answers

  • Uninstall the package I recommended then refer to the reply with 55 points on the link below.

    https://stackoverflow.com/questions/6649363/microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-machine

    And sorry for the late reply, currently in all day events at Microsoft which makes it hard to get time to reply.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Sid Williams Saturday, August 24, 2019 11:36 AM
    Monday, March 18, 2019 9:56 PM
    Moderator

All replies

  • Have you ever been able to connect to MS-Access?

    If not this means you need to install the drivers

    https://www.nuget.org/packages/Microsoft.Office.Interop.Access/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, March 18, 2019 4:41 PM
    Moderator
  • Hi,
    can you connect to the Access-DB from Visual Studio 2017 via Server Explorer?

    Can you successfully test connection via udl?


    --
    Viele Grüsse / Best Regards
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Monday, March 18, 2019 4:49 PM
  • I did that but problem still persist.
    Monday, March 18, 2019 4:50 PM
  • Try changing the target CPU to x86

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Monday, March 18, 2019 4:53 PM
  • I did that but problem still persist.
    Usually when this happens you are building to 64 bit and need to change to 32 bit under project properties or right click on solution explorer, select configuration manager and set to x86 for your project compile/build.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, March 18, 2019 4:57 PM
    Moderator
  • No, I tried to connect but I get the following error

    Monday, March 18, 2019 4:58 PM
  • tried that, but still not working.
    Monday, March 18, 2019 4:58 PM
  • Uninstall the package I recommended then refer to the reply with 55 points on the link below.

    https://stackoverflow.com/questions/6649363/microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-machine

    And sorry for the late reply, currently in all day events at Microsoft which makes it hard to get time to reply.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Sid Williams Saturday, August 24, 2019 11:36 AM
    Monday, March 18, 2019 9:56 PM
    Moderator