我收到一条我不明白的错误消息。我的MainWindow包含用于打开另一个名为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
在ListMaintenance窗口中,我有:
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
并关闭表单:
Private Sub btnExit_Click(sender As Object, e As RoutedEventArgs) Handles btnExit.Click
Me.Hide()
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
该表确实具有该约束,但我所做的只是打开并关闭表单。没有其他的。如何将新的子行添加到我的表中?