Click here to Skip to main content
15,908,274 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried the code below for add and save
But when i install it from other computer
It says .. cannot find updateable query

Is this a good add button code?

I still dont know how to use the insert into query
Can u give me some examples??

What I have tried:

* add button
VB
ElementaryBindingSource.AddNew()
Update()

* Save button
VB
Dim con as oledbConnection = new OledbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\Acer\Documents\school.accdb")
con.Open()
Try
ElementaryBindingSource.EndEdit()
ElementaryTableAdapter.Update(SchoolDataSet.Elementary)
Update()
MessageBox.Show("Data Saved")
Catch ex As Exception
MessageBox.Show(ex.Message)
End try
Posted
Updated 24-May-20 23:41pm
v2
Comments
RickZeeland 25-May-20 1:31am    
And how do you define ElementaryBindingSource ?

There is no such thing as "automatically". YOU have to provide some method of making the database location known. Usually, for an Access database, this is in a known folder under C:\ProgramData, a well-known location.

Either that, or you ask the user where the database is.

DO NOT put the database anywhere under C:\Program Files. Users do not have write access to files under that folder.
 
Share this answer
 
Comments
Maciej Los 25-May-20 5:41am    
5ed!
Beginner213456 25-May-20 6:17am    
Can the ms access database still be updated if the database is encrypted?

Thank you
Dave Kreskowiak 25-May-20 10:48am    
That depends on what you mean by "encrypted". If you're using a database password, do not make it longer than 14 characters and keep the choice of characters to alphanumeric. The password also has to be specified in the connection string, in plain text.

To add the database password to the connection string, just add the following to the end of your existing connection string:
;Jet OLEDB:Database Password=password;


If you want security on the database, don't use an Access database. Use SQL Server instead.
If you want to use an .accdb database file then the Access Database Engine ("ACE") must be installed on each machine. The installer is available for download here:
Download Microsoft Access Database Engine 2010 Redistributable from Official Microsoft Download Center[^]

Another idea if you do not need specific Access 2010 features:
convert your .accdb file to an .mdb file and use the Jet database engine that is already installed on all Windows machines.
Your application must be 32 bits for this to work (x86).
 
Share this answer
 
v4
Comments
Maciej Los 25-May-20 5:41am    
5ed!
In addition to solution #1 by DaveKreskowiak and solution #2 by RickZeeland
Do not store connection string in code! Use app.config file (or similar one), then you'll be able to easy change it or set it up during installation of your app on customer computer!

For further details, please see:
Connection Strings and Configuration Files - ADO.NET | Microsoft Docs[^]
How to store and retrieve custom information from an application configuration file by using Visual C#[^]
Configuring Apps by using Configuration Files | Microsoft Docs[^]
 
Share this answer
 
v2
Comments
Beginner213456 25-May-20 6:51am    
Is there a way to a code to correct
The
Operation must use an updatable query?
When you converted it to an installer
And installed it in a new computer
Maciej Los 25-May-20 8:11am    
Please, read what i said...
You need to get connection string from configuration file. During installation, you need to write necessary data into configuration file (including database file name).
See:
Change app.config applicationsettings during install[^]
Create a Custom Setup For Changing App.config[^]

BTW: you have to add empty database file to installer to be able to install it.

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