Solved

Data entered in Access table via VB seem to work, but missing next time file is opened.

Posted on 2014-01-05
4
823 Views
Last Modified: 2014-01-13
I have used MS Access 2013 to create a db-file with some data. I have then written some code in VB.NET that opens and access the data. I can create new records, and I can page through them back and forth and all seems fine. But when I run my program again, the data I entered has gone missing. I use
    Private Function storeData(ByVal mySql As String) As Boolean
        Dim ret As Boolean = False
        Dim ac As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & myPath)
        Try
            Using ac
                Dim myCommand = New System.Data.OleDb.OleDbCommand(mySql, ac)
                myCommand.Connection.Open()
                myCommand.ExecuteNonQuery()
                myCommand.Connection.Close()
            End Using

            ret = True
        Catch ex As Exception
            MsgBox("There is something wrong." & _
                   vbNewLine & ex.ToString, MsgBoxStyle.Exclamation, "SQL Error")
        End Try
        Return ret
    End Function

Open in new window

The SQL command looks something like this:
Insert into NAD(Name,Address,Postnumber,Telefonnumber,Epostaddress,Webpage) values('Thor','Oslo','0575','999 88 777','epost@epost.no','www.web.com');

Open in new window

and seem to work fine, and when I browse through the table using my program after having entered a new record, I can see the new records. But when I close the program and reopens it, or query the DB from outside, the newly entered data have disappeared. What am I missing? Do I need som kind of file save or commit or something?
0
Comment
Question by:IverErling
  • 2
4 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39757907
Check the location of where the Access DB file is. Then go to the programs project folder debug\bin directory and see if there is a copy there, if so open that version of the DB file and see if the records are there.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 400 total points
ID: 39757955
ExecuteNonQuery returns an Integer that indicates the number of rows affected by the command. Check its value.

If it is zero, then the command did not add the data to the table in the database.

If it is more than zero, then the data was inserted. In such a case, as Fernando suggested, you might be looking at 2 copies of the database and might be inserting in the wrong one. If myPath contains a relative path, this can easily arise.

If this is the case and If you see the database file in your project, click on it and look at the Copy to Output Directory in the Properties window. You might need to change it to another value to adjust the way that you work with the database during development.
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 100 total points
ID: 39757975
Hi IverErling;

As @JamesBurger stated you might be using a local database file in your project and the reason for my questions in my post. If that is the case this web page will give you the steps you need to follow for the configuration you want.

How to: Manage Local Data Files in Your Project
0
 

Author Comment

by:IverErling
ID: 39763089
Thanks for your advice! I will check this as soon as I get a chance, hopefully within a day or two! So easy to miss such things ;-)

IVer
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now