Click here to Skip to main content
15,119,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI I am very new to vb.net
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 vb.net form , it is not saved. I use this below connection
VB
Dim PO_con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/Database1.accdb;")
PO_con.Open()

can anyone guide me. huge thanks in advance

What I have tried:

VB
Dim PO_con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/Database1.accdb;")
PO_con.Open()
Posted
Updated 2-Feb-21 2:51am
v2
Comments
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.
   
v3
Comments
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 vb.net 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.
vish2778 2-Feb-21 7:44am
   
can you please tell me what is |DataDirectory|
CHill60 2-Feb-21 8:49am
   
|DataDirectory| is like a shorthand for whereever your data is going to be stored. It saves you having to type out the full path whenever you want to use the data location in a connection string or path. You can change it using the AppDomain.SetData Method [^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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