无法通过VB 2010更新Access数据库

时间:2014-07-27 09:14:37

标签: database vb.net visual-studio-2010 ms-access-2010

忙于为学校做项目,我们差不多完成了它。 连接VB2010程序以使用表适配器访问2010。

问题:从visual studio 2010内部运行程序时,我们可以查看更新&插入记录就好了。但是当我创建一个安装文件时,将它安装到我的电脑上,运行它运行的程序,但只允许你查看记录(通过表格),但是一旦我们尝试更新/插入它就会出错。 (我们处理的一个例外)下面是其中一种形式的代码:真的只是想让它工作,一直在苦苦挣扎。

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

非常感谢任何帮助解决这个问题

提前感谢。

0 个答案:

没有答案