Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# database WinForm
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 -:
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 -:
 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 9-Mar-13 22:28pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Jayanta Chatterjee at 10-Mar-13 7:52am
   
You are right my database become read only after installation...
I solved It..
Thanks for Helping me...
Maciej Los at 10-Mar-13 8:34am
   
Good answer, my 5!
du[DE] at 10-Mar-13 8:38am
   
Thank you, Maciej! (:
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

1) If PID is numeric field, remove '.
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:
SELECT CInt(YES) AS YesValue, CInt(NO) AS NoValue, CInt(TRUE) AS TrueValue, CInt(FALSE) AS FalseValue;
  Permalink  
v2
Comments
Jayanta Chatterjee at 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 at 10-Mar-13 7:59am
   
You're welcome ;)
Please, mark this solution as "solved" (formally).
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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... Smile | :)
  Permalink  
Comments
Maciej Los at 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)

  Print Answers RSS
0 Marcin Kozub 310
1 OriginalGriff 248
2 Sergey Alexandrovich Kryukov 215
3 Richard MacCutchan 202
4 Praneet Nadkar 197
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 10 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100