Click here to Skip to main content
11,637,176 members (70,826 online)
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 21: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 4

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;
  Permalink  
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 stibee 313
1 jyo.net 295
2 OriginalGriff 295
3 himanshu agarwal 184
4 Sergey Alexandrovich Kryukov 154
0 OriginalGriff 9,031
1 Sergey Alexandrovich Kryukov 8,513
2 Mika Wendelius 6,922
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 18 Feb 2015
Copyright © CodeProject, 1999-2015
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