Reputation: 12747
I've downloaded the trial version of VB 2010 and made a small application that connects to an Access 2007 MDB file.
A couple of things are going wrong:
If I try to publish it, and then run the setup file generated, it says it can't find the .MDB file.
If I run it during development (F5), it runs fine, and when I enter new data into a DataGridView, I know it gets saved because when I close the session and hit F5 again, the newly entered data is still present. (The relevant code for updating the data is simple enough):
Me.Validate()
Me.MenuItemsBindingSource.EndEdit()
Me.MenuItemsTableAdapter.Update(Me.MenuOrdersDataSet.MenuItems)
Me.MenuOrdersDataSet.AcceptChanges()
But if I close the whole project and rerun it and view the DataGridView, or if I manually go and check out the .MDB file, it no longer has the newly entered data.
This is my connection code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MenuItemsTableAdapter.Fill(Me.MenuOrdersDataSet.MenuItems)
Dim con As New OleDb.OleDbConnection
Dim dbString As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
dbString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\MenuOrders.accdb"
con.ConnectionString = dbString
con.Open()
sql = "SELECT * FROM MenuItems"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "MenuItems")
con.Close()
End Sub
What's the matter? Are these problems related to having a trial version, or are there some other obvious problems I should be aware of?
Upvotes: 2
Views: 5760
Reputation: 59
I used to have the same problem, and I think I fixed it by setting my data source/ database Copy to Output Directory to "Copy if newer", located in the properties window for the MyDatabase.mdf file.
Sometimes the option can default to "Always" which explains why the data set resets every time you run the application.
Upvotes: 1
Reputation: 12747
Finally did the following to fix it.
In Solution Explorer I opened App.config and put the absolute path to the database in the connectionStrings
tag, replacing the default |DataDirectory|
text.
Not sure if this is the best thing to do..but it worked!
<connectionStrings>
<add name="MenuSystem.My.MySettings.MenuDBConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Administrator\Documents\MenuDB.accdb"
providerName="System.Data.OleDb" />
</connectionStrings>
Upvotes: 1