Using:
MS Access 2010
Visual Studio 2010 with Provider=Microsoft.ACE.OLEDB.12.0 Connection
I have 2 forms:
frmCustomers contains datagridview that launches
frmEdit used to edit record.
The issue I am having is my save button on frmEdit saves changes to the datagridview on frmCustomers but not to the database
frmCustomers:
Public Class frmCustomers
Private Sub frmCustomers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'AutoBillDataSet.Customer' table. You can move, or remove it, as needed.
Me.CustomerTableAdapter.Fill(Me.AutoBillDataSet.Customer)
End Sub
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Me.CustomerTableAdapter.Fill(Me.AutoBillDataSet.Customer)
Me.dgvCustomers.Refresh()
End Sub
Private Sub CustomerBindingSource_BindingComplete(ByVal sender As Object, ByVal e As BindingCompleteEventArgs) Handles CustomerBindingSource.BindingComplete
If e.BindingCompleteContext = BindingCompleteContext.DataSourceUpdate AndAlso e.Exception Is Nothing Then
e.Binding.BindingManagerBase.EndCurrentEdit()
End If
End Sub
Private Sub dgvCustomers_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvCustomers.CellDoubleClick
Dim editForm As New frmEdit
editForm.DataSource = Me.CustomerBindingSource(e.RowIndex)
editForm.ShowDialog()
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
Dim editForm As New frmEdit
editForm.DataSource = Me.CustomerBindingSource.Current
editForm.ShowDialog()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim Dr As DataRow
Dim dlgResult As DialogResult
Dr = AutoBillDataSet.Customer.Rows.Item(dgvCustomers.CurrentRow.Index)
dlgResult = MessageBox.Show("Are you sure you wish to DELETE this account?", "Confirm Deletion?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If dlgResult = DialogResult.Yes Then
Dr.Delete()
Me.Validate()
Me.CustomerBindingSource.EndEdit()
Me.CustomerTableAdapter.Update(AutoBillDataSet.Customer)
Me.AutoBillDataSet.AcceptChanges()
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
frmEdit:
Public Class frmEdit
Public Property DataSource() As Object
Get
Return Me.CustomerBindingSource.DataSource
End Get
Set(ByVal value As Object)
Me.CustomerBindingSource.DataSource = value
End Set
End Property
Private Sub frmEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'AutoBillDataSet.Customer' table. You can move, or remove it, as needed.
Me.CustomerTableAdapter.Fill(Me.AutoBillDataSet.Customer)
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Me.Validate()
Me.CustomerBindingSource.EndEdit()
Me.CustomerTableAdapter.Update(Me.AutoBillDataSet.Customer)
Me.AutoBillDataSet.AcceptChanges()
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class
Any thoughts or references are appreciated.
Thank you in advance.