Last post Feb 01, 2016 12:51 PM by Yeoman
Feb 01, 2016 08:41 AM|Yeoman|LINK
I have a ListView that uses the default functionality to insert new records.
I found that some records are not inserted into the database, without any error messages.
While debugging, I found that the values that should be inserted violate some foreign key constraints.
This must be the reason why they were not inserted.
However, no exception was thrown.
How can I see when something's wrong from the database point of view?
(Note that I modify the record in the InsertItem event).
Feb 01, 2016 08:58 AM|oned_gk|LINK
The error should come, Have you use TRY-CATCH when inserting data?
Feb 01, 2016 12:10 PM|Yeoman|LINK
I only implement ItemInserting and ItemInserted.
In ItemInserting I check FormViewInsertEventArgs evt.Values, and some values are set like this:
evt.Values["attr"] = myDropDownList.SelectedValue != "nil" ? myDropDownList.SelectedValue : null;
Here, "nil" is the value for "not selected".
When I first ran my code, I had forgotton to check for "nil", and therefore the foreign key constraint was violated.
No record was inserted. No message was shown. I had to debug this to find it out...
Feb 01, 2016 12:24 PM|PatriceSc|LINK
What if you check for e.Exception in the ItemInserted event? I would have to try to make 100% sure but if I remember the default behavior is to let you to handle exceptions (so if not dojng anything I'm afaraid they are just ignored).
Feb 01, 2016 12:51 PM|Yeoman|LINK
Thank you, this solved the problem!
I had a Response.Redirect in my ItemInserted code that loads the page with the newly inserted record. The exception error message must have been supressed by this redirect.
Now I check the e.Exception attribute, and if not null, I don't call the redirect. Now the exception screen is shown as expected!