IsNotAllowDBNullViolated方法在调用DataSet.Clear期间抛出NullReferenceException [英] IsNotAllowDBNullViolated method throws NullReferenceException during call to DataSet.Clear
问题描述
这是另一个奇怪的。我有一个带有两个表的DataSet:
OrderHeaders(主键是[OrderID])
- OrderID - Int32
- OrderName - String
OrderDetails(主键是[OrderID,DetailID])
- OrderID - Int32(与OrderHeaders表的'OrderID'列相关联)
- DetailID - Int32
- ItemName - String
OrderDetails表绑定到我的Windows应用程序中的DataGridView。 "OrderID"列是DataGridViewComboBoxColumn。我可以毫无问题地加载和显示网格中的数据。我甚至可以毫无问题地插入和删除行。坚持对数据库的更改可以完美地运行。但是,当我尝试使用新值刷新DataSet时,我一直遇到问题。当我调用DataSet的'Clear()'方法时,System.Data.DataColumn.IsNotAllowDBNullViolated()方法抛出NullReferenceException。例如,如果我的DataSet名为'dsOrders',并且我调用'dsOrders.Clear()'以从DataSet中删除所有数据,则会抛出异常!如果我首先设置'dsOrders.EnforceConstraints = False',然后调用'dsOrders.Clear()',然后重新强制执行约束,则在调用期间抛出异常以重新强制执行约束。我相信这必须是System.Data.DataColumn类的'IsNotAllowDBNullViolated()'方法中的错误。任何人都可以为我阐明这一点吗?
另一个注意事项:我在开发一个在DataSet中有两个以上DataTables的真实应用程序时遇到了这个bug。我试图在一个非常简化的测试应用程序中重现此错误。在测试应用程序中,当我调用DataSet的'Clear()'方法时抛出异常,但是如果我调用各个表的'Clear()'方法,则不会抛出异常。在实际应用程序中,无论是否在DataSet或各个表上调用"Clear()",都会抛出异常。在这两种情况下,我都确信我按照正确的顺序在表上调用'Clear()'方法(根据DataSet中的约束)。
你好,
我有类似的问题(尽管我没有在我的数据库和数据集中使用参照完整性contstaints)。
如果我将数据集。 EnforceConstraints属性设置为false,问题就解决了。
问候,mnb
Here's another weird one. I have a DataSet with two tables:
OrderHeaders (primary key is [OrderID])
- OrderID - Int32
- OrderName - String
OrderDetails (primary key is [OrderID, DetailID])
- OrderID - Int32 (tied to the OrderHeaders table's 'OrderID' column)
- DetailID - Int32
- ItemName - String
The OrderDetails table is bound to a DataGridView in my windows application. The column for 'OrderID' is a DataGridViewComboBoxColumn. I can load and display the data in the grid without any problems. I can even insert and delete rows without a problem. Persisting the changes to the database works flawlessly. However, I keep encountering a problem when I try to refresh the DataSet with new values. A NullReferenceException is being thrown by the System.Data.DataColumn.IsNotAllowDBNullViolated() method when I call the 'Clear()' method of my DataSet. For example, if my DataSet is named 'dsOrders', and I make a call to 'dsOrders.Clear()' to remove all data from the DataSet, an exception is thrown! If I first set 'dsOrders.EnforceConstraints = False', then call 'dsOrders.Clear()', and then re-enforce constraints, the exception is thrown during the call to re-enforce the constraints. I believe this must be a bug in the 'IsNotAllowDBNullViolated()' method of the System.Data.DataColumn class. Can anyone shed any light on this for me?
One other note: I encountered this bug during development of a real-world application that had more than two DataTables in the DataSet. I attempted to reproduce this bug in a very simplified test app. In the test app, the exception is thrown when I make a call to the 'Clear()' method of the DataSet, but the exception is NOT thrown if I make a call to the 'Clear()' methods of the individual tables. In the real-world application, the exception is thrown regardless of whether I make the call to 'Clear()' on the DataSet or the individual tables. In both cases, I have assured that I call the 'Clear()' method on the tables in the proper order (according to constraints within the DataSet).
Hello,
I have a similar problem (altough I did not use referential integrity contstaints in my database and dataset).
If I set the dataset.EnforceConstraints property to false, the problem was solved.
Regards, mnb
这篇关于IsNotAllowDBNullViolated方法在调用DataSet.Clear期间抛出NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!