Click here to Skip to main content
15,511,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI I am very new to
I am using data source of ms access. i used data source path like "d:\abc\myproject\database1.accdb" but i will create issue when i deploy and create package(making exe file) so i add that database1.accdb file to my project folder. the issue is when i save data to database by form , it is not saved. I use this below connection
Dim PO_con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/Database1.accdb;")

can anyone guide me. huge thanks in advance

What I have tried:

Dim PO_con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/Database1.accdb;")
Updated 2-Feb-21 2:51am
Richard MacCutchan 2-Feb-21 7:17am    
You need to provide more details as to exactly what happens when you run the application. If there are no errors then the data must be going somewhere.
vish2778 2-Feb-21 7:33am    
hi, there is no error but data goes somewhere else. can you please tell me if i use this below code then when data is stored "Source=|DataDirectory|/Database1.accdb "

1 solution

See answer here: Access database doesn't save data[^]

By default the |DataDirectory| points to your application folder, see:
sql - Where is |DataDirectory| defined? - Stack Overflow[^]

I would also change the slash before Database1.accdb into a backslash.
Share this answer
vish2778 2-Feb-21 7:27am    
HI RickZeeland, thanks for replying. i did same as mentioned but data is stored in bin/debug/database1.accdb folder and when i fetch value i use "Source=|DataDirectory|/Database1.accdb " which not showing latest data
Richard Deeming 2-Feb-21 7:30am    
You probably have an empty copy of the file in your project, set to always overwrite the copy in your project directory.

But storing the database in the same folder as the application is a bad idea. Users will require full control of the folder in order to update the database. But if your application is deployed to the "Program Files" directory, they will need to "run as administrator" to get that access.
vish2778 2-Feb-21 7:41am    
hi Richard, i dont understand that once i submit data from form then i close the project and open datbase from bin\debug, i can found new entry. but when I reopen that database1, that new entry disappered
Richard Deeming 2-Feb-21 8:03am    
As I said, you've got an empty version of your database file included in your project, and it's set to overwrite the file in the bin\debug folder every time you run the project.
RickZeeland 2-Feb-21 7:42am    
As Richard already pointed out it might be better to change |DataDirectory| to another location.

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