Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone
I have developed an application in VB.Net and Access 2007 where I am saving ,editing,searching, updating and reporting records from the database and everything is working fine except:
1. There are two access files one in the project folder (myprojectname\dbname) and one in the (myprojectname\bin\debug\dbname) and when i save a record it is being saved but in the (myprojectname\bin\debug\dbname) database and not in (myprojectname\dbname) database which creates a problem when i run the project again the record is nowhere now.
I use the following code for connectionstring
<br />
Imports System.Data.OleDb<br />
Module connection<br />
    Public Con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & Application.StartupPath & "\mydb.accdb")<br />
   <br />
End Module<br />

I also tried
<br />
    Public Con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=|DataDirectory|\mydb.accdb;")<br />

but all in vain.
Now, i request you that please help me in the correct way of dealing with access 2007 database in VB.Net
Note: mydb.aacdb is also in my solution explorer.

Thank you
Posted
Updated 10-Jan-15 6:22am
v3

Start off by not storing your DB in either location. It's a poor idea, as it will give huge problems in production - the application will be installed in the "Program Files" folder which is write protected for security.

Instead, consider using a "safer" place: Where should I store my data?[^] - it's in C#, but it's pretty much the same in VB.
 
Share this answer
 
Comments
sarfarazbhat 10-Jan-15 22:40pm    
Sir could not get it. Is there some simple way. Or some sample code for VB.net.
Every time you compile your project the database file in the project folder is copied to the target bin folder when you run the app. This operation overwrites the file database you modified the last time you ran the app.

Don't keep your database file as part of the project. Store the database in a place that is accessible to all users on the machine. Look at the Environment.GetFolderPath[^] method and the the CommonApplicationData[^] folder.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900