Reputation: 47
I've faced with a strange behavior, when I try to change EnforceConstraints value "false" > "true" it throws a NullReferenceException.
dataSet1.EnforceConstraints = true;
The most strange thing is that exception is thrown when I try to save data for three times.
1. Create data (new row in dataTable1). Save it.
2. Change some field value. Save it.
3. Change the same data. Try to save it but got an exception.
4. If I change the same data and try to save it again, I'll get the exception again, but if I don't, all the data will be saved perfectly.
Note1: Exception is not thrown when I work with data which was created, saved and form with this data was reloaded.
Note2: All the difference in behaviour between (1, 2) and 3 points of scenario is happen when I call currencyManager.EndCurrentEdit(); of a control, related to my dataSet1. If I try to change EnforceConstraints value during debug one step before and one step after EndCurrentEdit() in points 1 and 2 of my scenario, debugger will show an exception. But in point 3 one step after calling EndCurrentEdit() I can change EnforceConstraints value in debugger from "false" to "true" and back without any problem.
PS: I understand that this information can be not enought, but the project is very huge and I need some idea, how find the reason of my NullReferenceException.
I need just some more information about currencyManager.EndCurrentEdit() and EnforceConstraints that we have in MSDN. Or may be I missed smth or it's a bug of Microsoft?
Thank you.
Upd.:
StackTrace:
at System.Data.DataColumn.IsNotAllowDBNullViolated()
at System.Data.DataSet.EnableConstraints()
at System.Data.DataSet.set_EnforceConstraints(Boolean value)
at MyProject.MyMethod() in d:...\SomeFileName.cs:line 9795
Exception Message:
"Object reference not set to an instance of an object."
Upvotes: 1
Views: 440