保存子表数据的问题 [英] Problem to save Child table data

查看:86
本文介绍了保存子表数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试从Form1保存MS Access子数据。子表由子表datagrid组成,我在这里选择父列数据。



没有生成错误 - 但Access数据库不会更新!



表格代码如下:



 公开  Form1 
私有 Sub Form1_Load(发件人作为 对象,e As EventArgs)句柄 MyBase .Load
< span class =code-comment>' 在孩子之前加载父母
.ParentTableAdapter.Fill( Me .TestiDBDataSet.Parent)
Me .ChildTableAdapte r.Fill( Me .TestiDBDataSet.Child)
结束 Sub

私有 Sub ChildBindingNavigatorSaveItem_Click(发件人< span class =code-keyword>作为 对象,e As EventArgs)句柄 ChildBindingNavigatorSaveItem.Click
尝试
.Validate()
' 为所有BindingSources调用EndEdit
Me .ParentBindingSource.EndEdit()
Me .ChildBindingSource.EndEdit()
.TableAdapterManager.UpdateAll(TestiDBDataSet) )
MsgBox( 数据更新
Catch ex As 异常
MsgBox( 数据更新失败
结束 尝试
结束 Sub

私有 Sub ChildDataGridView_enter()句柄 ChildDataGridView.Enter
' 在添加子行之前,您必须将父行发送到数据表
.ParentBindingSource.EndEdit()
结束 Sub

结束





PS。我还为两个关系和外键选项设置了Child和Parent数据关系约束。



PS。我也调试过,在构建期间,TestiDBDataSet将被正确更新。



在所有这些之后,MS Access数据库没有更新,但是在那里生成了MS Access Record Locking信息。正确的时间标签。



怎么了?任何信息赞赏...

解决方案

你好,在等待帮助的同时,我设法通过各种选项进行大量测试后由我自己解决问题。最后所有与Form1代码一起使用:



 公共  Form1 

私有 Sub Form1_Load(发件人作为 对象,e As EventArgs)句柄 MyBase .Load
.ParentTableAdapter.Fill( Me .TestiDBDataSet.Parent)
。 ChildTableAdapter.Fill( Me .TestiDBDataSet.Child)
End Sub

私有 Sub ChildBindingNavigatorSaveItem_Click(发件人< span class =code -keyword>作为 对象,e 作为 EventArgs)句柄 ChildBindingNavigatorSaveItem.Click
Me .Validate()
Me .ChildBindingSource.EndEdit()
Me .TableAdapterManager.UpdateAll( Me .TestiDBDataSet )
结束 Sub

结束





必不可少表格如何选择父数据到ChildDataGridView表:



数据(将列类型设置为DataGridViewCompoBoxColumn)

- DataPropertyName = PickParent

- DataSource = TestiDBDataSet

- DisplayMember = Parent.Parents

- ValueMember = Parent.ID



外观:设置DisplayStyle = Nothing



希望这对任何有类似问题的用户都有帮助。


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:

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...

解决方案

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:

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.


这篇关于保存子表数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆