I have deployed my application to be ready for use by another user (another computer), but when I try to add the data to the database I get the error
Operation must use an updatable query
The error is like this (This is when I already deployed my program and run under application, not under Visual Studio):
But it works perfectly under visual studio, the image like this (note that, the error on the image above appear once I click the submit button, it supposed to stored in the database, and display it on the datagridview as like image below):
And also I got another problem, the delete function is not running, the error on the add and delete appear once I deployed my program, but I will post that on another thread.
How do I solve this?
When a Visual Studio application is under development it resides in a folder to which the developer has read/write access. This is obviously necessary since the developer needs to be able to edit the source code files. If you place a database file "in with the code" then the application can update the database file because it is in a "writable" location.
However, if on deployment the database file stays "with the code" and the installer puts the files (i.e., the executable file and the database file) into
%ProgramFiles%
on the target machine (for example,C:\Program Files\MyApplication
) then the average user will not have write access to that location. Files in%ProgramFiles%
are normally restricted to read-only to protect the system from malware.Some people will try and configure the installer to grant write access to normal users for some file(s) or folder(s) under
%ProgramFiles%
but that is a Bad Idea™. The installer should really copy the database file to a location that is normally read/write for the intended user(s): either%USERPROFILE%
(for a specific user), or%PUBLIC%
(for all users).