dcsimg
Results 1 to 3 of 3

Thread: Operation must use an updateable query" error

  1. #1

    Thread Starter
    Hyperactive Member Joye's Avatar
    Join Date
    Jul 2009
    Posts
    256

    Operation must use an updateable query" error

    So I have a datagridview which connected to a (.mdb) database.
    And when using Microsoft Access databases with ADO, it is necessary to give the user Write permissions on the directory containing the .mdb file. This is because Jet creates an .ldb file to handle database locking. So I might need to give read/write permission on the program folder because Jet may create temporary files in this directory or just give read/write permission on the (.mdb) file it self.

    So because of that I can't update the database programmatically and I see (Operation must use an updateable query)note.

    How to apply that on my following Code to make it possible to update the database from the program?

    Code:
        Private Sub Button58_Click(sender As Object, e As EventArgs) Handles Button58.Click
            If Text1.Text = TextJSN.Text Then
                MessageBox.Show("Duplicated Job Sequence Number")
                GoTo line6
            End If
            Select Case MessageBox.Show("Are you sure you want to SAVE current 2K information to the 2K LOG? ", "Saving to 2K LOG", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
    
                Case MsgBoxResult.Yes
    
                    If Text1.Text.Trim.Length = 0 Or Text2.Text.Trim.Length = 0 Or Text3.Text.Trim.Length = 0 Or Text4.Text.Trim.Length = 0 Or Text5.Text.Trim.Length = 0 Then
    
                        MessageBox.Show("Make sure all required data are entered and there are no blank entries, Check (JOB SEQUENCE NUMBER) field.", "Blank Entries",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning)
    
                    Else
    
                        Try
                            LOGBindingSource.AddNew()
                            TextJSN.Text = Text1.Text
                            TextDEP.Text = Text2.Text
                            TextEQ.Text = Text3.Text
                            TextDATE.Text = Text4.Text
                            TextNAME.Text = Text5.Text
                            Me.Validate()
                            Me.LOGBindingSource.EndEdit()
                            Me.LOGTableAdapter.Update(_2K_Writer2_0DBDataSet.LOG)
                            MessageBox.Show("Saved Successfully", "Data Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
                            SaveChanges.Text = "1"
                        Catch ex As Exception
                            'MessageBox.Show("Error Occurred While Saving Data")
    
                        End Try
    
                    End If
                Case MsgBoxResult.Cancel
                Case MsgBoxResult.No
    
            End Select
    
            Me.WindowState = FormWindowState.Maximized
            Button56.Text = "Mid Form"
            Panel4.Size = New Size(363, 93)
            Label25.Text = "2"
            Panel3.Size = New Size(366, 93)
            Label24.Text = "2"
    
    
    line6: End Sub
    I hope I made it clear
    Thank you.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,354

    Re: Operation must use an updateable query" error

    Quote Originally Posted by Joye View Post
    So I might need to give read/write permission on the program folder
    No, you should not do that... not only is it often not an option, but it will also enable foolish users to accidentally break your program, and malicious software to infect your program.

    What you should do is store the database (and any other writeable files your program uses) in proper locations that are meant to be writeable, such as one of the AppData folders.

    For information on some of those folders, see the article Where should I store the files that my program uses/creates? (ignore the code etc, because it is not for .Net).


    Also note that using GoTo is a bad idea (it makes your code harder to read), and should be avoided if possible. In this case, you can simply change "GoTo line6" to "Exit Sub".

    It is also a very bad idea to have Try-Catch with an empty Catch block, because it means the errors happen but you don't know about it (so in this case the user might think the data saved, but it didn't). Even if you uncomment your MessageBox code, they aren't much wiser - they (and you) have no idea what the actual problem was, only that there was "a problem". It would be better to remove the Try-Catch than have your current situation.

  3. #3

    Thread Starter
    Hyperactive Member Joye's Avatar
    Join Date
    Jul 2009
    Posts
    256

    Re: Operation must use an updateable query" error

    Quote Originally Posted by si_the_geek View Post
    No, you should not do that... not only is it often not an option, but it will also enable foolish users to accidentally break your program, and malicious software to infect your program.

    What you should do is store the database (and any other writeable files your program uses) in proper locations that are meant to be writeable, such as one of the AppData folders.

    For information on some of those folders, see the article Where should I store the files that my program uses/creates? (ignore the code etc, because it is not for .Net).


    Also note that using GoTo is a bad idea (it makes your code harder to read), and should be avoided if possible. In this case, you can simply change "GoTo line6" to "Exit Sub".

    It is also a very bad idea to have Try-Catch with an empty Catch block, because it means the errors happen but you don't know about it (so in this case the user might think the data saved, but it didn't). Even if you uncomment your MessageBox code, they aren't much wiser - they (and you) have no idea what the actual problem was, only that there was "a problem". It would be better to remove the Try-Catch than have your current situation.
    Very informative
    Thank you very much
    I Will try that and respond and follow all your recommendations because they simply make sense and right to do from the beginning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width