Solved

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

Posted on 2014-01-05
4
835 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

914 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

20 Experts available now in Live!

Get 1:1 Help Now