Wpf 错误消息使我困惑

Wpf 错误消息使我困惑,wpf,vb.net,Wpf,Vb.net,我收到一条我不理解的错误消息。My Main window包含打开另一个名为ListMaintenance的窗口的代码: Private Sub mnuListMaintenance_Click(sender As Object, e As RoutedEventArgs) Try Dim win As Window = New ListMaintenance win.Show() Catch ex As Exception Debug.WriteLine("In

我收到一条我不理解的错误消息。My Main window包含打开另一个名为ListMaintenance的窗口的代码:

Private Sub mnuListMaintenance_Click(sender As Object, e As RoutedEventArgs)
    Try
    Dim win As Window = New ListMaintenance
    win.Show()
Catch ex As Exception
    Debug.WriteLine("In Main")
    Debug.WriteLine(ex.ToString)
End Try
End Sub
在窗口列表维护中,我有:

Private Sub winListMaintenance_Loaded(sender As Object, e As RoutedEventArgs) Handles winListMaintenance.Loaded
    Try
        <get data from DB and load dataset tables>
    Catch ex As Exception
        Debug.WriteLine("Loaded")
        Debug.WriteLine(ex.ToString)
    End Try
End Sub
第一次打开ListMaintenance时,没有错误消息。第二次打开表单时,我得到以下信息:

A first chance exception of type 'System.Data.InvalidConstraintException' occurred in System.Data.dll
Loaded
System.Data.InvalidConstraintException: Cannot clear table StandardEntryCategories because ForeignKeyConstraint relSEC_SE enforces constraints and there are child rows in StandardEntries.
at System.Data.ForeignKeyConstraint.CheckCanClearParentTable(DataTable table)
at System.Data.DataTable.Clear(Boolean clearAll)
at System.Data.DataTable.Clear()
at PIM.PIMDataSetTableAdapters.taStandardEntryCategories.Fill(StandardEntryCategoriesDataTable dataTable) in f:\PIM\PIMDataSet.Designer.vb:line 3555
at PIM.ListMaintenance.winListMaintenance_Loaded(Object sender, RoutedEventArgs e) in f:\PIM\ListMaintenance.xaml.vb:line 10

表确实有那个约束,但我所做的只是打开和关闭表单。没有别的了。新的子行是如何添加到我的表中的?

如果只是隐藏第二个窗口,那么每次要显示它时初始化它是没有意义的。所以eigther Init;显示关闭并重复或初始化一次;显示隐藏显示隐藏@MrPauilch我隐藏了第二个窗口,因为我知道我无法关闭它,然后在同一个应用程序中重新打开它。它不是每次显示时都初始化的,因为Window_Loaded事件只在窗体的初始加载时触发,而不是在窗体再次可见时触发。我不理解你其余的评论;这是什么意思?初始化?我已经阅读了相关文档,似乎与此无关。我很感谢你的评论,但请详细说明你所说的。我说的“Init”是指创建窗口对象,特别是:Dim win As Window=New listmainment
A first chance exception of type 'System.Data.InvalidConstraintException' occurred in System.Data.dll
Loaded
System.Data.InvalidConstraintException: Cannot clear table StandardEntryCategories because ForeignKeyConstraint relSEC_SE enforces constraints and there are child rows in StandardEntries.
at System.Data.ForeignKeyConstraint.CheckCanClearParentTable(DataTable table)
at System.Data.DataTable.Clear(Boolean clearAll)
at System.Data.DataTable.Clear()
at PIM.PIMDataSetTableAdapters.taStandardEntryCategories.Fill(StandardEntryCategoriesDataTable dataTable) in f:\PIM\PIMDataSet.Designer.vb:line 3555
at PIM.ListMaintenance.winListMaintenance_Loaded(Object sender, RoutedEventArgs e) in f:\PIM\ListMaintenance.xaml.vb:line 10