0

busy working on a project for school and we are almost done with it. connected a VB2010 program to access 2010 using table adapters.

Problem: when running the program from inside visual studio 2010 we can view update & insert records just fine. But when I create a install file, install it onto my pc, run the program it runs but only allows you to view the records (via forms) but as soon as we try to update/insert it gives an error. (an exception which we handled) below is code from one of the forms: really just want to get this working, been struggling for so long.

Public Class EditProducts_Form

Private Sub Products_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
        'TODO: This line of code loads data into the 'ChaosComputers_DatabaseDataSet.CC_Products' table. You can move, or remove it, as needed.
        Me.CC_ProductsTableAdapter.Fill(Me.ChaosComputers_DatabaseDataSet.CC_Products)
    Catch FormLoadException As Exception
        MessageBox.Show("Unable to load database", "Error")
    End Try

End Sub

Private Sub btnExitProducts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExitProducts.Click
    If MessageBox.Show("Are you sure you want to exit the Product list? Any unsaved changes will be lost", "Confirm exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
        Me.Close()
    Else : Me.Show()

    End If
End Sub

Private Sub btnPreviousProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreviousProd.Click
    CCProductsBindingSource.MovePrevious()  'Will move to the previous record

End Sub

Private Sub btnNextProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextProd.Click
    CCProductsBindingSource.MoveNext()
End Sub


Private Sub btnAddNewProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNewProd.Click
    MessageBox.Show("Please enter the details of the new product in the blank text boxes provided", "Enter details", MessageBoxButtons.OK, MessageBoxIcon.Information)
    CCProductsBindingSource.AddNew() 'Adds the new record to the gridview
End Sub

Private Sub btnSaveProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveProd.Click
    Try 'Start of Exception Handling for Save Product Button
        Me.Validate()
        Me.CCProductsBindingSource.EndEdit()
        Me.CC_ProductsTableAdapter.Update(Me.ChaosComputers_DatabaseDataSet.CC_Products)
        MessageBox.Show("Product Successfully Saved", "Product saved", MessageBoxButtons.OK, MessageBoxIcon.Information)

    Catch SavebtnExcption As Exception
        MessageBox.Show("Error while saving data", "Error")
    End Try

    '*** Can maybe clear the text boxes after the product's been successfully saved.

    '*** Will have to include some sort of exception here, for when the record is not successfully added
End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    Try
        If MessageBox.Show("Are you sure you want to delete this product?", "Confirm delete", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
            CCProductsBindingSource.RemoveCurrent()
            Me.CC_ProductsTableAdapter.Update(Me.ChaosComputers_DatabaseDataSet.CC_Products)
        Else
            Me.Show()
        End If


    Catch DeletebtnException As Exception
        MessageBox.Show("Encountered an error while attempting to delete product", "Error")
    End Try

    '*** User must be prompted to ask if sure about the deletion ***
End Sub


End Class

Any help in solving this would be greatly appreciated

thanks in advance.

2
  • Did you know that the Exception object has a Message field that tells you exactly what is going wrong? If you catch the Exception and print that field probably you could have a better understanding of the reasons of the failure instead of a generic "FAIL" message like now. Please tell us the Exception.Message text
    – Steve
    Jul 27, 2014 at 9:40
  • @Steve Ok, I removod the catch on the save button. shows me the following: unhandled exception has occured.... operation must use an updateable query, when I click the details button the following shows: ************* Exception Text ************** System.Data.OleDb.OleDbException (0x80004005): Operation must use an updateable query. at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[]
    – J.C
    Jul 27, 2014 at 10:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.