Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a windows application in C# winform. when i run this in Visual Studio IDE It's fine(it select,insert and update the database records). then I make this to an setup project, after the setup installation when i tried to run, it select data from database table, but the problem is when i update & Insert records into that database table it give an error message "Operation must use an updateable query".

My code is -:
C#
conn = new OleDbConnection(@"Provider=microsoft.jet.oledb.4.0; Data Source=" + path + "\\PiyashData.mdb;Jet OLEDB:Database Password=power;");
                conn.Open();
cmdIn = new OleDbCommand();
DC.SelectSta("select * from Valid", "Valid");
        if (DC.dataSet.Tables["Valid"].Rows[0][0].ToString().CompareTo(textBox1.Text) == 0)
        {        
              DC.CmdStatement("update Valid set Pcheck=1 where PID='" + textBox1.Text + "'");
              MessageBox.Show("Successfully Updated!!!");
              this.Dispose();
        }

the Database table structure is -:
Field name ->> type
PID ->> text
Pcheck ->> Yes/No
I'm using Access database.

Here DC is an Database manipulation class.
DC CmdStatement methods is -:
C#
 public void CmdStatement(string stamet)
 {
    try
    {                
         cmdIn.Connection = conn;                
         cmdIn.CommandText = stamet;                
         cmdIn.ExecuteNonQuery();
    }
    catch (Exception e)
    {
         MessageBox.Show(e.Message);  
    }
}


thanks in Advanced....
Posted

Take a look at this answer, seems to be the same (at the first glance): operation must use an updateable query ms access[^]

One quite likely reason is that the user running the program doesn't have read-write access to the database file, especially if it is located in program files folder.

So check the directory and file permissions and moodify them if needed. You can also consider changing the location of the database file to another, more asily accessible folder.
 
Share this answer
 
Comments
JayantaChatterjee 10-Mar-13 7:52am    
You are right my database become read only after installation...
I solved It..
Thanks for Helping me...
Maciej Los 10-Mar-13 8:34am    
Good answer, my 5!
Leo Chapiro 10-Mar-13 8:38am    
Thank you, Maciej! (:
1) If PID is numeric field, remove '.
C#
DC.CmdStatement("update Valid set Pcheck=1 where PID=" + textBox1.Text);

2) In MS Access YES/NO | TRUE/FALSE field, every YES/TRUE value is -1 and every NO/FALSE is 0 (zero).
You can check it, using simple trick:
SQL
SELECT CInt(YES) AS YesValue, CInt(NO) AS NoValue, CInt(TRUE) AS TrueValue, CInt(FALSE) AS FalseValue;
 
Share this answer
 
v2
Comments
JayantaChatterjee 10-Mar-13 7:54am    
Sir, Thanks for Helping Me...
I Solved My Problem.. it's not with the query, it happened when i create the Setup project.. :-)
Maciej Los 10-Mar-13 7:59am    
You're welcome ;)
Please, mark this solution as "solved" (formally).
i i faced this problem with windows form application and Ive found a simple solution that when you create your set up project and select the wanted project from the release folder don't select the database with it just run the project and go the application folder which will be created at the user machine then right click it chose add -> file select your database; remember to set the connection string path to same place where the application folder is located on the user machine example in app.config file for the origin application
example i have an application that will be installed on the drive D: in folder Named My Application
and the data base is in the same folder
connection string should be like this: Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\My Application \Access File.accdb;Jet OLEDB:Database Password=DbPassword;
 
Share this answer
 
Here's, How I solved My problem -:
when creating Setup project, there have a "Application Folder" in File System (right click on Setup project name from the solution Explorer -> View -> File System).
Just select "Application folder"(from right pane) and set the DefaultLocation property to "C:\" or any valid drive letter.
and then Rebuild, and Install...

Now your Database file will not be Read only... :-)
 
Share this answer
 
Comments
Maciej Los 10-Mar-13 8:36am    
+5!
Mark du[DE]'s answer as "solved", because your solution is based on Him/His suggestion.

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