VB.NET accessing MS Access Database

Hello,

I'm trying to figure out some basics with VB.net and interfacing with a MSAccess .accdb.

For the sake of this test, the .accdb file is located in the root directory of the project.  

I've already created a basic "Select" statement, and can pull data from my table within the .accdb.  That works fine.

It's the updates and inserts that I can't get to work.  The code below seems straightforward, and I've had this exact code work when connecting to an SQL server (with a change to connection string of course), so it's something about this access database.

The database itself is brand new, just created it, and then added a single table with a small sample of data.  There is no security setup on it that I know of.  I also set Windows File permissions to Everyone -> Full Access to rule out permissions there.

The code does not generate any errors, it simply doesn't cause a change to the DB.  

Does anyone have any thoughts?

Thanks
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=filename.accdb;Persist Security Info=False;"



     Dim ds As New Data.DataSet()
     Dim da As New Data.OleDb.OleDbDataAdapter()
     Dim conn As New Data.OleDb.OleDbConnection(connString)

     conn.Open()

     Dim cmd As New Data.OleDb.OleDbCommand("UPDATE TableName SET Manufacturer = 'abc123' WHERE MsdsID = 9")
        cmd.Connection = conn
        txtTemp.Text = cmd.ExecuteNonQuery()


        conn.Close()

Open in new window

compsol1993Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Are you looking at the correct copy of the DB? If you added the DB file to your project, it should be getting copied to the bin directory when you build your application. The copy in bin is the one that will be updated, not the one in your project directory.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
compsol1993Author Commented:
Thanks for the feedback, I just confirmed and it is not making any modifications to the .accdb file in bin/Debug

Good point though, I didn't think of that.
0
käµfm³d 👽Commented:
Did you manually include the DB into the bin directory (i.e. open up folder in Explorer and copy/paste file), or did you "add an existing item" to your project and have it copied to output on build?
0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

compsol1993Author Commented:
I did the add existing.

Ok, I figured something out, but I'm not sure why.

I understand that when it is built, a new copy of the .accdb file gets copied to the Debug directory.  So I built it, ran the code, then checked the .accdb file in that directory, no change.

So then I changed from Debug to Release, re-ran, opened the db in the Release directory, and then it did work.

Any thoughts on why?
0
käµfm³d 👽Commented:
If you go to Solution Explorer, select the DB file, then hit F4 (open Properties pane), what does the "Copy to Output Directory" property say (for Debug and Release)?
0
compsol1993Author Commented:
It's set to always copy.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.