Click here to Skip to main content
15,885,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm trying to save the MS Access Child data from Form1. Child table is consisting of Child table datagrid where I am picking the Parent column data.

No errors are generated - but the Access Database will not be updated!

The Form code is as follows:

VB.NET
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Load parent before child
        Me.ParentTableAdapter.Fill(Me.TestiDBDataSet.Parent)
        Me.ChildTableAdapter.Fill(Me.TestiDBDataSet.Child)
    End Sub

    Private Sub ChildBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles ChildBindingNavigatorSaveItem.Click
        Try
            Me.Validate()
            ' Call EndEdit for all BindingSources
            Me.ParentBindingSource.EndEdit()
            Me.ChildBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(TestiDBDataSet)
            MsgBox("Data updated")
        Catch ex As Exception
            MsgBox("Data update failed")
        End Try
    End Sub

    Private Sub ChildDataGridView_enter() Handles ChildDataGridView.Enter
        ' You must commint the parent row to the datatable before adding child rows
        Me.ParentBindingSource.EndEdit()
    End Sub

End Class


PS. I also have set the Child and Parent data relation constraint for "Both relation and Foreign key" option.

PS. I also have debugged that during the build the TestiDBDataSet will be updated correctly.

After all this the MS Access Database is not updating but there's generated MS Access Record Locking information at correct time label.

What's wrong?? Any information appreciated...
Posted
Updated 23-Nov-15 8:57am
v4
Comments
Suvendu Shekhar Giri 22-Nov-15 2:14am    
Put a break point in the line UpdateAll() is called and check whether the dataset contains the updated correct values or not.
Member 12111641 22-Nov-15 2:49am    
I think that the Dataset will be updated but actual Database not.

Just set the Quick Watch for the break point and there's a error message on UpdateAll:

Error BC30451: "UpdateAll" is not declared. It may be inaccesible due to its protection level.

How to solve this?

1 solution

Hello, in a meantime while waiting help I managed to solve the problem by me own as follows after heavy testing with various options. Finally all works with Form1 code:

VB.NET
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.ParentTableAdapter.Fill(Me.TestiDBDataSet.Parent)
        Me.ChildTableAdapter.Fill(Me.TestiDBDataSet.Child)
    End Sub

    Private Sub ChildBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles ChildBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.ChildBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.TestiDBDataSet)
    End Sub

End Class


It is essential in a form how to select the parent data into a ChildDataGridView- table:

Data (Set column type as DataGridViewCompoBoxColumn)
- DataPropertyName = PickParent
- DataSource = TestiDBDataSet
- DisplayMember = Parent.Parents
- ValueMember = Parent.ID

Appearance: Set DisplayStyle = Nothing

Hope this can be helpfull for any other users with similiar problem.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900